Wrapper Classes | Autoboxing | Unboxing | Java
π What is Autoboxing?
Autoboxing is the automatic conversion of a primitive type into its corresponding wrapper class.
β Example:
Java automatically converts int β Integer.
π What is Unboxing?
Unboxing is the reverse process β converting a wrapper class object back to a primitive type.
β Example:
Java converts Integer β int.
π¦ Wrapper Classes in Java
| Primitive Type | Wrapper Class |
|---|---|
byte |
Byte |
short |
Short |
int |
Integer |
long |
Long |
float |
Float |
double |
Double |
char |
Character |
boolean |
Boolean |
π§ Why Use Wrapper Classes?
- Used in Collections (like
ArrayList,HashMap) - Provide utility methods (e.g.,
Integer.parseInt()) - Allow null values
- Enable autoboxing/unboxing
π Real Example:
β Summary:
| Concept | Description | Example |
|---|---|---|
| Autoboxing |
int β Integer
|
Integer a = 10; |
| Unboxing |
Integer β int
|
int b = a; |
| Wrapper | Object version of primitive | Integer, Double, Boolean |
![μλ°] java κΈ°λ³Έ νμ
μ wapper(λνΌ) ν΄λμ€, λ°μ±κ³Ό μΈλ°μ±](https://blog.kakaocdn.net/dn/C2EnJ/btr9RwuWIXb/hEY5YIDhTpkZXKn25Hlkd1/img.png)