CHAPTER 9
WRAPPER CLASSES
When we give gifts, we wrap them nicely in a box. The gift may be a doll or a toy car or something else. The box and the glossy paper around it make it attractive. We have worked with simple data types. Now Java wants to wrap them and make them more attractive (useful). For this, Java provides an interesting concept of wrapper classes.
9.1 Introduction
We have studied the basic data type float
. It holds floating-point number. Now Java provides a class Float
. As identifiers are case sensitive, Float
and float
are different. The new class Float
is for storing floating-point values only. But it is a class, a wrapper class.
Similarly, a bare number of type int
is wrapped nicely in a class Integer
. We know that classes have ...
Get Programming with Java now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.