☕ Java Beginner

What is a wrapper class in Java?

Answer

Wrapper classes are object representations of Java's eight primitive types: Byte, Short, Integer, Long, Float, Double, Character, and Boolean. They are needed because generics and collections like List, Map, and Set cannot work with primitives — they require objects. Wrapper classes also provide utility methods (e.g., Integer.parseInt(), Double.isNaN()) and constants (e.g., Integer.MAX_VALUE). Java 5 introduced autoboxing and unboxing to automatically convert between primitives and their wrapper classes, making the distinction mostly transparent in day-to-day code.