KnowledgeBoat Logo
|

Computer Applications

Explain the terms, Autoboxing and Auto-unboxing in Java.

Java Library Classes

8 Likes

Answer

The automatic conversion of primitive data type into an object of its equivalent wrapper class is known as Autoboxing. For example, the below statement shows the conversion of an int to an Integer.

Integer a = 20;

Here, the int value 20 is autoboxed into the wrapper class Integer variable myinteger.

Auto-unboxing is the reverse process of Autoboxing. It is the automatic conversion of a wrapper class object­ into its corresponding primitive type. For example,

Integer myinteger = 20;   
int myint = myinteger;

Here, the object myInteger is automatically unboxed into primitive type int variable myint when the assignment takes place.

Answered By

4 Likes


Related Questions