Java Format - Java Formatter.flush()








Syntax

Formatter.flush() has the following syntax.

public void flush()

Example

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

//from w w  w.j  a  va2  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 java2s.com";
      formatter.format("Hello %s !", name);

      // print the formatted string
      System.out.println(formatter);

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

The code above generates the following result.