Wrapper classes are object representations of primitive types. They let primitives be used where objects are required, like in collections, generics or with methods expecting Objects.

  • Java collections like List, Map, etc. can’t store primitives
  • You need wrappers to use generics
  • Useful in Autoboxing + Unboxing

Primitive ↔ Wrappers

PrimitiveWrapper Class
byteByte
shortShort
intInteger
longLong
floatFloat
doubleDouble
charCharacter
booleanBoolean

Example

List<Integer> nums = new ArrayList<>();
nums.add(5);          // int β†’ Integer (autoboxing)
int n = nums.get(0);  // Integer β†’ int (unboxing)

Common Methods

Integer.parseInt("42");      // String β†’ int
Double.parseDouble("3.14");  // String β†’ double
 
Integer x = Integer.valueOf(100);  // Creates Integer object

Parent: _Casting & Types