Java Program to illustrate Autoboxing and Unboxing

With the Autoboxing and Unboxing features, we can convert primitive data types to the wrapper class types automatically. The compiler generates a code implicitly to convert the primitive type to the wrapper class type and vice-versa.

Program:


import java.util.Stack;
public class test
{
public static void main(String args[])
{
Stack myStack=new Stack();
myStack.push(10); // Autobox
myStack.push.(20); // Autobox
int stackSum= myStack.pop()+ myStack.pop(); // Unboxing
System.out.println("The Top Element of the Stack is:"+ myStack.pop());
System.out.println("The next Top Element of the Stack is:"+ myStack.pop());
System.out.println("The Sum of two Element of the Stack is:"+ stackSum);
}
}