Java Format - Java Formatter() Constructor


Formatter() constructor from Formatter has the following syntax.

public Formatter()


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

//from ww w . j  a v a  2  s. c  om
import java.util.Formatter;
import java.util.Locale;

public class Main {

   public static void main(String[] args) {

      Formatter formatter = new Formatter();

      // 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.