3.15 The Integer, Double, Character, and Other Wrapper Classes

Most programs use a combination of primitive data types and objects. Some class methods, however, will accept only objects as arguments, so we need some way to convert a primitive data type into an object. Conversely, there are times when we need to convert an object into a primitive data type. For example, let’s say we have a GUI where we ask users to type their age into a text box or a dialog box. We expect the age to be an int value; however, text boxes and dialog boxes return their values as Strings. To perform any calculations on an age in our program, we will need to convert the value of that String object into an int.

For these situations, Java provides wrapper classes

Get Java Illuminated, 5th Edition now with O’Reilly online learning.

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