538 Part II: The Java Library
Specifier Effect
%E Causes theesymbol that indicates the exponent to be displayed in uppercase.
%G Causes theesymbol that indicates the exponent to be displayed in uppercase.
%H Causes the hexadecimal digitsathroughfto be displayed in uppercase asA
throughF.
%S Uppercases the corresponding string.
%T Causes all alphabetical output to be displayed in uppercase.
%X Causes the hexadecimal digitsathroughfto be displayed in uppercase asA
throughF.Also, the optional prefix0xis displayed as0X, if present.
For example, this call:
fmt.format("%X", 250);
creates this string:
FA
This call:
fmt.format("%E", 123.1234);
creates this string:
1.231234E+02
Using an Argument Index
Formatterincludes a very useful feature that lets you specify the argument to which a format
specifier applies. Normally, format specifiers and arguments are matched in order, from left
to right. That is, the first format specifier matches the first argument, the second format
specifier matches the second argument, and so on. However, by using anargument index,
you can explicitly control which argument a format specifier matches.
An argument index immediately follows the%in a format specifier. It has the following
format:
n$
wherenis the index of the desired argument, beginning with 1. For example, consider this
example:
fmt.format("%3$d %1$d %2$d", 10, 20, 30);
It produces this string:
30 10 20