Monthly Archives: October 2012

Boxing UnBoxing AutoBoxing Manual Boxing

Boxing refers to the conversion of a primitive to a corresponding wrapper instance, such as from an int to a java.lang.Integer.

Unboxing is the conversion of a wrapper instance to a primitive type, such as from Byte to byte.

	int i = 10;
	Integer iObj = new Integer(100);

	iObj = i;//boxing conversion
	i = iObj;//unboxing conversion

Manual boxing ( Boxing ) vs Autoboxing

Integer ii;
int i;

OLD WAY : Manual boxing
ii = new Integer(i); // convert from int to Integer
i = ii.intValue();
// convert from Integer to int
NEW WAY : Autoboxing, conversions are automatically applied.
ii = i; // convert from int to Integer
i = ii;
// convert from Integer to int

MIT Pakistan