This week's book giveaway is in the Programmer Certification forum. We're giving away four copies of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
A formatter String is a String that usually contains one or more substitution macros that begin with '%' and end with a letter. For instance, '%s' would be replaced by a String from the argument list that follows the format String.
The two most common methods that know how to parse and process a format String and the following arguments are:
System.out.printf("Hi there, %s",name);
The '%s' is replaced by the contents of the variable 'name'.
Format macros can have a variety of modifiers between the '%' and the closing letter 's'.
System.out.printf("Hi there, %-10s (good to see you again)",name);
The '%-10s' is replaced by the contents of the variable 'name'. The '10' tells the formatter to allocate a minimum of 10 characters for the name and if there are less to pad them with spaces. The '-' tells the formatter to left justify the name within the 10 characters.