Wrapper class in java

Wrapper class in java

1 min read

To make java fully object-oriented, wrapper Class was introduced.
It is used to convert a primitive data type into an object and vice versa.

A wrapper class is divided into two categories:

  • Autoboxing,that converts primitive data type to object.
  • Unboxing, that converts object to primitive data type.


Eight classes of java.lang package are known as wrapper class in java.

Primitive typeWrapper class
boolean Boolean
charCharacter
byte Byte
shortShort
int Integer
longLong
float Float
doubleDouble

Example:-

 class wrapper
 {
 public static void main(String[] args)
 {
 int i=10;
 //Autoboxing
 Integer a=Integer.valueof(i);
 //Integer a=i;   JVM will internally add "Integer.valueof(i);
//Unboxing
 Integer x=new Integer(10);//object of wrapper class
 int y=x.intvalue();
 }
 }

Tags:
Choose your Reaction!
Leave a Comment