Saturday , February 23 2019
Home / Java / Wrapper class in Java

Wrapper class in Java

Wrapper classes are used to convert primitive into object and object into primitive. Each of Java’s eight primitive data types has a class dedicated to it. These are known as wrapper classes, because they “wrap” the primitive data type into an object of that class.

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. For example, upto JDK1.4, the data structures accept only objects to store. A data type is to be converted into an object and then added to a Stack or Vector etc. For this conversion, the designers introduced wrapper classes.

All the wrapper classes (Integer, Long, Byte, Double, Float, Short) are subclasses of the abstract class Number.The Number class is part of the java.lang package.

Since J2SE 5.0, autoboxing and unboxing feature converts primitive into object and object into primitive automatically. The automatic conversion of primitive into object is known and autoboxing and vice-versa unboxing.

Primitive data type Wrapper class
byte Byte
short Short
int Integer
long Long
float Float
double Double
char Character
boolean Boolean

Wrapper class Example: Primitive to Wrapper

Wrapper class Example: Wrapper to Primitive



About admin

Check Also

Internal Working of HashMap in Java

In this article, we will see how hashmap’s get and put method works internally. What ...

Leave a Reply