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 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.