Explain autoboxing and unboxing.
To add any primitive to a collection, you need to explicitly box (or cast) it into an appropriate wrapper class. It is not possible to put any primitive values, such as int or char, into a collection. Collections can hold only object references.
While taking out an object out of the collection, it needs to be unboxed. Hence the autoboxing and unboxing features of Java 5 can be used to avoid these steps.
All that needs to be done in a code is declaring class autoboxunbox.
What is Auto boxing and unboxing?
Autoboxing is the process of converting a primitive type data into its corresponding wrapper class object instance.
Example: Integer number = new Integer (100); // number is now refers to the object 100
Unboxing is the process of converting a wrapper instance into a primitive type.
Example: Integer number = new Integer (100);
int num = number;// without type casting number would be changed into int type