Java Wrapper Class
Java Wrapper Class
Java Wrapper Class
The wrapper class in Java provides the mechanism to convert primitive into
object and object into primitive.
Since J2SE 5.0, autoboxing and unboxing feature convert primitives into
objects and objects into primitives automatically. The automatic conversion
of primitive into an object is known as autoboxing and vice-versa unboxing.
The eight classes of the java.lang package are known as wrapper classes in
Java. The list of eight wrapper classes are given below:
boolean Boolean
char Character
byte Byte
short Short
int Integer
long Long
float Float
double Double
autoboxing
Unboxing
public class Ex
byte b=10;
short s=20;
int i=30;
long l=40;
foat f=50.0F;
double d=60.0D;
char c='a';
boolean b2=true;
//Autoboxing: Converting primitives into objects
Byte byteobj=b;
Short shortobj=s;
Integer intobj=i;
Long longobj=l;
Float foatobj=f;
Double doubleobj=d;
Character charobj=c;
Boolean boolobj=b2;
//Printing objects
byte bytevalue=byteobj;
short shortvalue=shortobj;
int intvalue=intobj;
long longvalue=longobj;
foat foatvalue=foatobj;
double doublevalue=doubleobj;
char charvalue=charobj;
boolean boolvalue=boolobj;
//Printing primitives
Output:
Byte object: 10
Short object: 20
Integer object: 30
Long object: 40
Character object: a
byte value: 10
short value: 20
int value: 30
long value: 40
foat value: 50.0
char value: a