Wrapper Classes
Explore how to use Java wrapper classes to represent primitive data as objects. Learn about Integer and Character classes, methods like parseInt, autoboxing, and comparing wrapper objects. This lesson helps you understand converting between primitive types and objects in Java.
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 ...