Wrapper classes are used to convert any data type into an object. The primitive data types are not objects; they do not belong to any class; they are defined in the language itself. Sometimes, it is required to convert data types into objects in Java language
What is a Wrapper class?
A wrapper class wraps or encloses a data type and gives it an appearance of an object. You can also get the primitive datatype from the object.
Observe the following example.
int x = 100;
Integer iObj = new Integer(x);
The int data type (x) is converted into an object (iObj) with the help of an Integer class. This can be used whever an object is required.
The following code can be used to unwrap the object iObj and obtain the primitive datatype.
int y = iObj.intValue();
System.out.println(y); // prints 100
intValue() is a method of Integer class that returns an int data type.
Why Wrapper classes?
To convert primitive data types into objects and vice versa.