Autoboxing and unboxing are automatic conversions performed by the Java compiler between primitive data types and their corresponding wrapper classes.
Introduced in Java 5, these features eliminate manual conversion boilerplate so primitives can seamlessly interact with object-based APIs and collections.
Feature | Autoboxing | Unboxing |
|---|---|---|
Direction | Primitive → Wrapper Object (e.g., | Wrapper Object → Primitive (e.g., |
int a = 10;
Integer obj = a; // Autoboxing
Integer x = 20;
int b = x; // Unboxing