Java Reference
In-Depth Information
the output is either the string "true" or the string "false" depending on
the argument's value, otherwise the output is the string "true" .
The h and H conversions are hash code conversions. If the argument
is null then the output is the string "null" . Otherwise, the output
is the string obtained by passing the object's hashCode result to In-
teger.toHexString .
The s and S conversions are string conversions. If the argument is null
then the output is the string "null" . Otherwise, if the argument im-
plements the Formattable interface (see next section) then its formatTo
method is invoked to produce a customized output; otherwise, the out-
put is the result of invoking toString on the argument. The # flag can be
passed only to a Formattable argument, and its effect is determined by
the object.
For all the general conversions, the width specifies the minimum number
of characters, while the precision indicates the maximum. Spaces will be
used to pad the output to the minimum width if necessary. The preci-
sion is applied first so if it is smaller than the width, the output will be
truncated to that maximum size. The only flag applicable is the flag to
left-justify the output. If the flag is given then a width must be given.
22.1.6. Custom Formatting
A class can support custom formatting by implementing the Formattable
interface, which defines the single method formatTo . If an instance of
that class is passed as an argument for a string conversion ( s or S ) then
its formatTo method will be invoked, passing the current formatter as an
argument.
public void formatTo(Formatter formatter, int flags, int width, int
precision)
Outputs the representation of the current object by appending
the desired text to the destination of the given formatter, ob-
 
Search WWH ::




Custom Search