Java Format - Java Formatter.locale()


Formatter.locale() has the following syntax.

public Locale locale()


In the following code shows how to use Formatter.locale() method.

/* w ww. j  a v  a  2 s. c  o m*/
import java.util.Formatter;
import java.util.Locale;

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";
      formatter.format("Hello %s !", name);

      // print the formatted string with default locale


The code above generates the following result.