Java autoboxing and unboxing - Explain autoboxing and unboxing.

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
What is Map and SortedMap interface?
Java Map and SortedMap - Maps are used to store the key-Value pairs...
Java Externalizable Interface
Explain the concepts of Externalizable Interface, Define the purpose of Externalizable Interface...
What is transient and volatile modifiers?
When serializable interface is declared, the compiler knows that the object has to be handled so as so be able to serialize it...
Post your comment