Basic example of AutoBoxing and Unboxing in Java

Here is the simple program for printing basic example of AutoBoxing and Unboxing in Java.

Source Code

import java.util.Stack;
class stacks
  public static void main(String args[])
   Stack mystack = new Stack();
   mystack.push(new Integer(10));
   mystack.push(new Integer(20));
   Integer a=(Integer)mystack.pop();
   Integer b=(Integer)mystack.pop();
   int c=a.intValue()+b.intValue();
   System.out.print("\nTotal : "+c);
   //J2SE 5.0
   Stack<Integer>ustack =new Stack<Integer>();
   ustack.push(10);// Autobox
   int x=ustack.pop()+ustack.pop();  // Unbox
   System.out.print("\nTotal : "+x);
To download raw file Click Here


Total : 30
Total : 50

Learn All in Tamil © Designed & Developed By Tutor Joes