Autoboxing and Unboxing in Java
Before comprehension autoboxing and unboxing in java, we should recognize what is wrapper class. So let’s investigate it.
Wrapper Class
A wrapper class folds over a crude information type and gives it an article appearance.
This wrapper class article can be utilized at whatever point the crude information type is required as an item.
Autoboxing in Java
The way toward changing over crude information type into wrapper
class object naturally is known as autoboxing. This element was included in JDK 1.5.
The model for autoboxing is given beneath. Till JDK 1.4 we
need to physically do the transformation of crude information type into a wrapper class
also, the other way around utilizing wrapper class technique yet from JDK 1.5 it is finished naturally.
Till JDK 1.4
int x=10;
Integer i=new Integer(x); //boxing
From JDK 1.5
int x=10;
Integer i=x; //autoboxing
Unboxing in Java
The way toward changing over wrapper class object into
crude information type naturally is called unboxing.
Till JDK 1.4
int x=10;
Integer i=new Integer(x); //boxing
int z=i.intValue(); //unboxing
From JDK 1.5
int x=10;
Integer i=x; //autoboxing
int z=i; //unboxing
A rundown of crude information type with their comparing
a wrapper class is given beneath.
Primitive Data Type | Wrapper Class |
byte | Byte |
short | Short |
int | Integer |
long | Long |
float | Float |
double | Double |
char | Character |
boolean | boolean |
Video Tutorial to Explain Autoboxing and Unboxing in Java:
On the off chance that you discovered anything incorrect or missing in the above instructional
exercise, at that point please notice it by remarking underneath.