Conversions and Java Print Streams - Character conversions (Page 2 of 5 )
Character conversions can be applied to char and java.lang.Character objects. They can also be applied to byte,short,int, and the equivalent type-wrapper objects if the integer falls into the range of Unicode code points (0 to 0x10FFFF). These conversions are:
%c A lowercase Unicode character
%C An uppercase Unicode character
Boolean conversions can be applied to boolean primitive values and java.lang.Boolean objects. They can also be applied to all object types, in which case they’re considered to be true if the object is nonnull and false if it is null. All other primitive types are considered to be true, regardless of value. These conversions are:
%b “true” or “false”
%B “TRUE” or “FALSE”
These conversions are not localized. Even in France, you’ll see “true” and “false” instead of “vrai” and “faux.”
There are two more conversions that can be applied to any object and also to primitive types after autoboxing. These are:
%h/%H The lowercase/uppercase hexadecimal form of the object’shashCode, or “null” or “NULL” if the object is null.
%s/%S The result of invoking the object’sformatTo() method if it implementsFormattable; otherwise, the result of invoking itstoString()method, or “null” if the object is null. With%S, this value is then converted to uppercase.
Example 7-4 prints a URL (which does not implementFormattable) in all of these formats.