wrapper classes
wrapper classes
3
Wrapper Classes
• Wrapper classes may contain static methods that help
manage the associated type
– For example, the Integer class contains a method to
convert digits stored in a String to an int value:
num = Integer.parseInt(str);
• Wrapper classes often contain useful constants
– For example, the Integer class contains MIN_VALUE and
MAX_VALUE for the smallest and largest int values
4
Wrapper Classes
• Boxing: the process of going from a value of a
primitive type to an object of its wrapper class
– To convert a primitive value to an "equivalent" class type
value, create an object of the corresponding wrapper class
using the primitive value as an argument
– The new object will contain an instance variable that
stores a copy of the primitive value
– Unlike most other classes, a wrapper class does not have a
no-argument constructor
Integer integerObject = new Integer(42);