G.8 Other Conversion Characters

The remaining conversion characters are b, B, h, H, % and n. These are described in Fig. G.10. Lines 9–10 of Fig. G.11 use %b to print the value of boolean (or Boolean) values false and true. Line 11 associates a String to %b, which returns true because it’s not null. Line 12 associates a null object to %B, which displays FALSE because test is null. Lines 13–14 use %h to print the string representations of the hash-code values for strings ”hello” and ”Hello”. These values could be used to store or locate the strings in a Hashtable or HashMap (both discussed in Chapter 20, Generic Collections). The hash-code values for these two strings differ, because one string starts with a lowercase letter and the other with ...

Get Java How to Program (early objects), 9/e 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.