Autoboxing and Unboxing

Reading Time: < 1 minute

Autoboxing and Unboxing is introduced in java since the version of 1.5. A

Autoboxing is the automatic conversation that when we convert a primitive type to its corresponding wrapper class;


int intPrimitive = 15;
		Integer intWrapper = new Integer(intPrimitive);
		double doublePrimitive = 15.10;
		Double doubleWrapper = new Double(doublePrimitive);

Unboxing is the reversed version of Autoboxing which is to transform the wrapper class to its corresponding primitive type


Integer intWrapper = new Integer(15);
		int intPrimitive = intWrapper;
		Double doubleWrapper = new Double(15.10);
		double doublePrimitive = doubleWrapper;

List of Primitives and Wrapper classes supplied in Java

Primitive type Wrapper class
boolean Boolean
byte Byte
char Character
float Float
int Integer
long Long
short Short
double Double