Java Autoboxing Example
Chapter:
Miscellaneous
Last Updated:
23-03-2017 19:48:29 UTC
Program:
/* ............... START ............... */
public class JavaAutoboxExample {
public static void main(String args[]) {
int a = 50;
Integer a2 = new Integer(a);// Boxing
Integer a3 = 5;// Boxing
System.out.println(a2 + " " + a3);
}
}
/* ............... END ............... */
Output
Notes:
-
The automatic conversion of primitive data types into its equivalent Wrapper type is known as boxing and opposite operation is known as unboxing.
- Java 5 onward we got support of Autoboxing and unboxing.
- Auto-boxing allows you to easily use collections of primitive values (such as a List, ...).
Tags
Autoboxing Example, Miscellaneous, Java