For every Java primitive data type there exists a corresponding Java wrapper class that can be used to add functionality to primitive types. The wrapper classes are found in the java.lang package. Table 6-5 lists the primitive types, their corresponding wrapper classes, and some methods of interest supplied by each wrapper class.
Primitive Type | Wrapper Class | Methods of Interest |
---|---|---|
char | Character | The Character class provides many class field constants and methods(). There are too many to list them all here. You’ve seen two Character static class methods in action in this chapter. They are isJavaIdentifierStart(char c), and isJavaIdentifierPart(char c). Other methods you may find immediately helpful include: toLowerCase(char c), toUpperCase(char c), and toTitleCase(char c). Take the time to look up this class in the Java platform API documentation. |
byte | Byte | parseByte(String s), toString(byte b), longValue(), intValue(), shortValue(), doubleValue(), floatValue(), toString() |
short | Short | parseShort(String s), intValue(), longValue(), byteValue(), doubleValue(), intValue(), floatValue(), toString() |
long | Long | parseLong(String s), intValue(), shortValue(), byteValue(), doubleValue(), floatValue(), toString() |
int | Integer | parseInt(String s), longValue(), floatValue(), shortValue(), byteValue(), doubleValue(), toString() |
float | Float | parseFloat(String s), byteValue(), shortValue(), longValue(), intValue(), doubleValue(), toString() |
double | Double | parseDouble(String s), floatValue(), byteValue(), shortValue(), longValue(), intValue(), toString() |
boolean | Boolean | getBoolean(String name), toString(Boolean b), toString() |