Wrapper Classes
In this lesson, we will introduce classes in the Java Class Library that represent primitive data as objects.
For each primitive data type, the Java Class Library contains a corresponding wrapper class. These classes enable us to represent primitive data as objects. They also contain constants that indicate the range of such data and provide useful methods for processing input data. It is these latter two features that are most important to us right now.
The class Integer
The class Integer
represents integers whose data type is int
. This class contains
two constants that indicate the range of int values. The constant Integer.MAX_VALUE
contains the largest int
value, 231 – 1
, and Integer.MIN_VALUE
contains the smallest value, –231
. Note that the data type of these constants is int
, not Integer
.
The static method parseInt
The class Integer
defines the static method parseInt
. It accepts a string containing an integer as its argument and returns an int
representation of that integer. For example, in the following program, parseInt
returns the int
value 5280:
Get hands-on with 1400+ tech skills courses.