Computer Applications
What is the need of wrapper classes when there are primitive datatypes ?
Java Library Classes
10 Likes
Answer
The need of wrapper classes when there are primitive data types are as follows:
- Java is an object oriented language where everything is used as objects. The wrapper classes enable a primitive value to be used as objects. As objects, they can be used with all types of classes and their methods.
- Wrapper classes provide many ready-to-use utility methods such as converting a string having primitive type value to equivalent primitive form. For example, "10" can be converted to integer 10 using a wrapper class method.
- Primitive data types are passed by value, but objects are passed by reference. Wrapper classes facilitate passing primitives by reference, as an argument to a method, if so required.
Answered By
8 Likes