Boxing and unboxing:-
Boxing:-Boxing is the process of the converting the primitive data typoe to the object of the coresponding
Wrapper class or assigning the value of the data types the object..
For example :-
int a=10;
object obj;
obj=a;
Converting the int to the Integer.
![]() |
| Autoboxing and unboxing in java with examples|Difference between them |
Unboxing:-
This the process of the assigning the value of the pobject into the primitive datatype or converting the corresponding Wrapper class into the primitive data types.
See some information of Autoboxing and unboxing
Example1:-
class Demo1
{
public static void main(String args[])
{
Integer a=new Integer(12);
System.out.println(a);
int a1=10;
a=a1;//Auto boxing
System.out.println(a);
Boolean b1=new Boolean(true);
boolean b2=false;
b2=b1;//Unboxing
System.out.println(b1);
}
}
exapmle2:-
class Demo2
{
public static void main(String args[])
{
Boolean b=new Boolean("java");
if(b)//unboxing
{
System.out.println("s");
}
if(b=true)//Autoboxing
{
System.out.println("A");
}
}
}
