Java Reference
In-Depth Information
else {
// Left-justified flag '-' is not used
}
You can use your FormattablePerson objects with format specifiers using string conversion 's' and 'S'
as shown below:
FormattablePerson fp = new FormattablePerson("Ken", "Smith");
System.out.printf("%s %n", fp );
System.out.printf("%#s %n", fp );
System.out.printf("%S %n", fp );
System.out.printf("%#S %n", fp );
Ken Smith
Smith, Ken
KEN SMITH
SMITH, KEN
Character Formatting
Character formatting may be applied to the values of char primitive data type or Character objects. It can also be
applied to the values of byte , Byte , short , Short , int , or Integer types if their values are valid Unicode code points.
You can test if an integer value represents a valid Unicode code point by using the isValidCodePoint(int value)
static method of the Character class.
The conversion character for character formatting is 'c' . Its uppercase variant is 'C' . The flag '#' and the
precision are not supported for character formatting. The flag '-' and width have the same meaning as in the context
of the general formatting. The following snippet of code demonstrates the use of character formatting:
System.out.printf("%c %n", 'a');
System.out.printf("%C %n", 'a');
System.out.printf("%C %n", 98);
System.out.printf("'%5C' %n", 100);
System.out.printf("'%-5C' %n", 100);
a
A
B
' D'
'D '
Numeric Formatting
Numeric formatting can be broadly classified into two categories:
Integral number formatting
Floating-point number formatting
 
Search WWH ::




Custom Search