Home Exam Help ICT Tutorials Government Jobs General Knowledge Courses Health Travel

In Java, each primitive data type has a corresponding wrapper class. This tutorial explains what wrapper classes are and when to use them.

What are Wrapper Classes?

Wrapper classes provide a way to use primitive data types as objects. Java's collection framework (e.g., ArrayList) works only with objects, so wrapper classes are needed to store primitive values in collections.

PrimitiveWrapper Class
intInteger
doubleDouble
charCharacter
booleanBoolean
floatFloat
longLong
byteByte
shortShort

Autoboxing and Unboxing

Autoboxing is the automatic conversion of a primitive to its wrapper class. Unboxing is the reverse. Since Java 5, these conversions happen automatically:

Integer num = 5;       // autoboxing
int val = num;         // unboxing

For more on data types, see Java Data Types. For OOP concepts, see OOP in Java.