What is Autoboxing and Unboxing in Java?

Autoboxing
Converting a primitive value into an object of the corresponding wrapper class is called autoboxing.

Unboxing
Converting an object of a wrapper class to its corresponding primitive value is called unboxing.

Example:

// Java program to illustrate the concept of Autoboxing and Unboxing
public class AutoboxingUnboxingDemo {

	public static void main(String[] args) {

		// Creating an Integer object with value 25
		Integer x = new Integer(25);

		// Unboxing the object
		int y = x;

		// Autoboxing of char
		Character ch1 = 'A';

		// Unboxing of char
		char ch2 = ch1;

		System.out.println("Value of x: " + x);
		System.out.println("Value of y: " + y);
		System.out.println("Value of ch1: " + ch1);
		System.out.println("Value of ch2: " + ch2);

	}

}

Author: Mahesh

Technical Lead with 10 plus years of experience in developing web applications using Java/J2EE and web technologies. Strong in design and integration problem solving skills. Ability to learn, unlearn and relearn with strong written and verbal communications.