Introduction
In Java, everything is related to an object. Wrapper classes in Java convert data types into objects since primitive data types are not objects. So to convert them into objects we need wrapper classes in Java.
Wrapper Classes in Java
Wrapper classes are used to convert data types into objects. As the name suggests, a wrapper class wraps a data type and provides it an object scenario. Wrapper classes can also unwrap the specific object and return the data type. These wrapper classes are in the java.lang package. We can also use an example of a toffee. It is wrapped in a wrapper to prevent it from dust. The consumer takes the toffee, unwrap it and eat it.
int a = 50;
Integer ir = new Integer(a);
In the code above the int data type, a is converted into an object.
int b = ir.intValue();
System.out.println(b);//prints 50
The code above is used to unwrap the object.
List of Wrapper Classes in Java
| Primitive data type | Wrapper class |
| byte | Byte |
| short | Short |
| int | Integer |
| long | Long |
| float | Float |
| double | Double |
| char | Character |
| boolean | Boolean |
Hierarchy of Wrapper Classes

Example



Sandeep SharmaPosted Nov 17, 2013, 1:41 PM
In one of the java interview I got rejected due to this question "what is wrapper class in java". So thanks for sharing this basic and informative topic.