Saturday, May 18, 2013

AutoBoxing and UnBoxing in Java with Example


After Java 1.5 is introduced the concept of AutoBoxing and UnBoxing (Auto-UnBoxing) comes into picture. In Java when the primitive types like int, double etc. are converted into their object class type (wrapper class type) like Integer, Double then it is called as AutoBoxing.

Example:-

Integer i=10; //Here AutoBoxing is happening from Primitive to Wrapper

When this wrapper object is transformed into its primitive type then it is called as UnBoxing.

Example:-

int iInt=i; //Here Unboxing is happening from Wrapper to Primitive
System.out.println("The value of int is " + iInt);

No comments:

Post a Comment