2.5. Wrapper classes

[2.5] Develop code that uses wrapper classes such as Boolean, Double, and Integer.

Java defines a wrapper class for each of its primitive data types. The wrapper classes are used to wrap primitives in an object, so they can be added to a collection object. They enable all types to be treated like object instances. Wrapper classes help you write cleaner code, which is easy to read. For this exam, you should be able to write code that uses these wrapper classes.

2.5.1. Class hierarchy of wrapper classes

All the wrapper classes are immutable—classes that don’t allow changes to the state of their instances after initialization. They share multiple usage details and methods. Figure 2.18 shows their hierarchy. ...

Get OCA Java SE 8 Programmer I Certification Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.