The original plan for J2SE version 1.4 is to include support for formatted output. These features are not included in the published release because of the time limit and the ability to make the release of the new version impossible. Now with Tiger, there is an intrinsic support for printing formatted strings.
For those who have never contacted C from the start with Java programming, or, for those who do not have enough knowledge of C, the format string is odd text strings that specify the output characteristics of a set of variables. Instead of connecting strings together with a plus sign (such as FirstName + "+ lastName"), instead of providing a string description output and supplying arguments to the placeholder in the replacement string at the end of the method call: string s = String.Format ("%1 $ s)%2$s ", FirstName, LastName).
Formatter class
First, let's analyze the new Java.util.Formatter class. You may not use this class directly, but it provides an internal mechanism for formatting. In the Javadoc of this class, you see a table that describes the supported formatting options. The range of options ranges from specifying the precision and digits of floating-point numbers in a format such as%7.4f, to the%tt of the formatted time, to the format of the third parameter%3$s.
Formatted output with Formatter is a two-step process: Create a Appendable object to store the output, and use the format () method to place the formatted content in the object. The following is a list of the implementations of the Appendable interface:
BufferedWriter
Chararraywriter
Charbuffer
FileWriter
Filterwriter
LogStream
OutputStreamWriter
PipedWriter
PrintStream
PrintWriter
StringBuffer
StringBuilder
StringWriter
Writer