English

Write a difference between Autoboxing and Unboxing.

Advertisements
Advertisements

Question

Write a difference between Autoboxing and Unboxing.

Distinguish Between
Advertisements

Solution

Feature Autoboxing Unboxing
Definition Converts a primitive type into its corresponding wrapper class object. Converts a wrapper class object back into its primitive type.
Direction Primitive → Object (e.g., int to Integer). Object → Primitive (e.g., Integer to int).
Java Example Integer obj = 25; int num = obj;
Behind the Scenes Java uses Integer.valueOf(25) under the hood. Java uses obj.intValue() under the hood.
Common Use Case When adding primitive numbers into collections like an ArrayList When performing mathematical operations on values stored inside objects.
shaalaa.com
  Is there an error in this question or solution?
Chapter 5: Library Classes - Exercises [Page 134]

APPEARS IN

Rupa Pandit Computer Applications [English] Class 10 ICSE
Chapter 5 Library Classes
Exercises | Q 4. (v) | Page 134
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×