Java Format - Java Formatter.format(String format, Object ... args)








Syntax

Formatter.format(String format, Object ... args) has the following syntax.

public Formatter format(String format,   Object ... args)

Example

In the following code shows how to use Formatter.format(String format, Object ... args) method.

import java.util.Formatter;
import java.util.Locale;
/*from  w  ww  .j ava  2s  .  co 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("Hello %s !", name);

      // print the formatted string with default locale
      System.out.println(formatter + " " + formatter.locale());

   }
}

The code above generates the following result.