Tuesday, March 3, 2015

Autoboxing and Autounboxing

Autoboxing is the process of converting the primitive type to Wrapper type(object) and unboxing is the vice versa .Below example illustrate the same.

package autobox;

public class AutoBoxExample {

 public static void main(String[] args) {
  // TODO Auto-generated method stub
  int i=10;
  Integer i1=new Integer(i);//boxing
  Integer i2=20;//boxing
  int i3=i2;//unboxing
  System.out.println(i1);
 }

}

output:
10 >>>Final
------------------------------------------------------------------------------------------------------------