Wrapper Classes in Java – What Every Developer Should Know
A wrapper class is a reference type that encapsulates a primitive value in an object. The Java standard library provides a dedicated wrapper for each of the eight primitive data types, as well as one for void. These classes reside in the java.lang package and are designed to bridge the gap between primitives and objects, enabling you to store primitive values in collections, work with generics, and use a wealth of utility methods for parsing, comparison, and conversion. Since Java 5, autoboxing and unboxing allow you to seamlessly convert between a primitive and its corresponding wrapper without explicit calls to valueOf() or xxxValue(), making the code cleaner while still relying on the underlying wrapper machinery.
The table below lists every primitive type alongside its immutable wrapper counterpart. Immutability means once a wrapper instance is created, its value cannot change – a critical property when using them as keys in maps or as elements in thread‑safe contexts. Common operations like conversion from a String (Integer.parseInt()), obtaining a wrapper instance (Boolean.valueOf(true)), and extracting the primitive (double d = dObj.doubleValue()) are all defined directly on these classes.
Primitive - Wrapper
boolean - java.lang.Boolean
byte - java.lang.Byte
char - java.lang.Character
double - java.lang.Double
float - java.lang.Float
int - java.lang.Integer
long - java.lang.Long
short - java.lang.Short
void - java.lang.Void