| Primitive | Size | Wrapper |
|---|---|---|
| byte | 1 byte | Byte |
| short | 2 bytes | Short |
| int | 4 bytes | Integer |
| long | 8 bytes | Long |
| float | 4 bytes | Float |
| double | 8 bytes | Double |
| char | 2 bytes (Unicode) | Character |
| boolean | JVM specific | Boolean |
Autoboxing converts a primitive to its wrapper automatically (int → Integer); unboxing is the reverse. Collections can only store objects, so they use wrappers.
Integer a = 5; // autoboxing
int b = a; // unboxing
int n = Integer.parseInt("42");
String s = String.valueOf(99);
Integer x = 127, y = 127;
System.out.println(x == y); // true (cached -128..127)
Integer p = 128, q = 128;
System.out.println(p == q); // false (different objects)
System.out.println(p.equals(q)); // true