Autoboxing and Unboxing in Java


Autoboxing and unboxing allow automatic conversion between primitive types and their corresponding wrapper classes.

Source Code

List list = new ArrayList();
list.add(5); // Autoboxing int to Integer
int n = list.get(0); // Unboxing Integer to int

Java automatically handles the conversion between primitives and wrappers, making collections more versatile.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments