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

Advertisements

Tagged: , , , ,

One thought on “Boxing UnBoxing AutoBoxing Manual Boxing

  1. Kalpana November 26, 2013 at 6:12 pm Reply

    Well done , simple and precise

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: