Java Format - Java Formatter(Appendable a, Locale l) Constructor


Formatter(Appendable a, Locale l) constructor from Formatter has the following syntax.

public Formatter(Appendable a,   Locale l)


In the following code shows how to use Formatter.Formatter(Appendable a, Locale l) constructor.

//w ww.  j a  va 2 s.  co 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

      // flush the formatter. Here it does nothing.
      System.out.println("Formatter Flushed.");

The code above generates the following result.