Wrapper Classes in Java


Java provides wrapper classes for all eight primitive types. These classes encapsulate a primitive value in an object.

Source Code

Integer myInt = 5; // Autoboxing of int to Integer
int myPrimitiveInt = myInt; // Unboxing of Integer to int

Use wrapper classes when you need to store primitive values in collections like ArrayList, or to utilize methods provided by these classes.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments