Why are there wrapper classes in Java?

Viewed 79807

I know what a wrapper class is, they wrap primitive types (e.g. int, double, etc) to objects of their respective class.

But, why do we need Wrapper classes in the first place? Why not simply go with primitive types where we have them?

9 Answers

Wrapper classes are used to convert any primitive type into an object.The primitive data types are not objects, they do not belong to any class, they are defined in the language itself. While storing in data structures which support only objects, it is required to convert the primitive type to object first, so we go for wrapper class.

Related