Java Formatter.format(Locale l, String format, Object ... args)
Syntax
Formatter.format(Locale l, String format, Object ... args) has the following syntax.
public Formatter format(Locale l, String format, Object ... args)
Example
In the following code shows how to use Formatter.format(Locale l, String format, Object ... args) method.
import java.util.Formatter;
import java.util.Locale;
/*from w w w . j a v a2s.c o m*/
public class Main {
public static void main(String[] args) {
StringBuffer buffer = new StringBuffer();
Formatter formatter = new Formatter(buffer, Locale.US);
// format a new string
String name = "from java2s.com";
formatter.format(Locale.US,"Hello %s !", name);
// print the formatted string with specified locale
System.out.println(formatter + " " + formatter.locale());
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.util »
Java Tutorial »
java.util »