Let there be printf
Tiger brings printf-style formatted output to the world of Java programming; and this month, columnist John Zukowski discusses all facets of the C-inspired support for printf and format strings.
The original plan for the 1.4 release J2SE included support for formatted output. Probably due to time constraints and the fact that the feature wasn't a release driver, the capabilities were left out of the release. Now with Tiger, there is built in support for printing with format strings.
For those who grew up with Java programming and never touched C
or those who haven't lived in a C world for some time, format
strings are those funky text strings that specify output
characteristics for a bunch of variables. Instead of just
concatenating strings together with the plus sign (as in
firstName + " " + lastName), you provide a single
string to describe the output and provide the
arguments to fill the placeholders in that string at the end of the
String s = String.format("%1$s %2$s", firstName, lastName).