Autoboxing and Unboxing

Java Data Types (Primitive and Non primitive / Reference), Java Variables (Local Variables, Instance Variables and Static or Class Variables), Explicit Declaration of Data Types & Variables, Purpose of Variables, Variable naming restrictions and Data Conversion.
Post Reply
swathi
Posts: 134
Joined: Fri Nov 23, 2018 2:52 am

Autoboxing and Unboxing

Post by swathi » Thu Dec 06, 2018 9:06 am

What is Autoboxing and Unboxing ?

manoj
Posts: 87
Joined: Fri Nov 23, 2018 5:29 am

Re: Autoboxing and Unboxing

Post by manoj » Thu Dec 06, 2018 9:07 am

Autoboxing: Converting a primitive value into an object of the corresponding wrapper class is called autoboxing.
For example, converting int to Integer class.

Unboxing: Converting an object of a wrapper type to its corresponding primitive value is called unboxing.
For example conversion of Integer to int.

kishore
Posts: 55
Joined: Thu Jan 03, 2019 3:57 am

Re: Autoboxing and Unboxing

Post by kishore » Sat Jan 05, 2019 5:07 am

Autoboxing:
***************
-->Converting a primitive value into an object of the corresponding wrapper class is called autoboxing. For example, converting int to Integer class. The Java compiler applies autoboxing when a primitive value is:
Passed as a parameter to a method that expects an object of the corresponding wrapper class.
Assigned to a variable of the corresponding wrapper class.

Unboxing:
************
-->Converting an object of a wrapper type to its corresponding primitive value is called unboxing. For example conversion of Integer to int. The Java compiler applies unboxing when an object of a wrapper class is:
Passed as a parameter to a method that expects a value of the corresponding primitive type.
Assigned to a variable of the corresponding primitive type.

Post Reply

Return to “Java Data Types & Variables”