Object Wrappers for Primitives

Each of the eight primitive types we have just seen has a corresponding class type, predefined in the Java library. For example, there is a class java.lang.Integer that corresponds to primitive type int. These class types accompanying the primitive types are known as object wrappers and they serve several purposes:

  • The class is a convenient place to store constants like the biggest and smallest values the primitive type can store.

  • The class also has methods that can convert both ways between primitive values of each type and printable Strings. Some wrapper classes have additional utility methods.

  • Some data structure library classes only operate on objects, not primitive variables. The object wrappers provide ...

Get Just Java™ 2 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.