Home  >  Core Java

Example of Formatter in Java

By Arvind Rai, May 31, 2013
java.util.Formatter in Java, supports layout justification and alignment. It works like printf. Formatter is not thread safe. We need to use synchronization method or block. The Object of Formatter can be created in different way. Find the example.
FormatterDemo.java
package com.concretepage.util;
import java.util.Formatter;
import java.util.Locale;
public class FormatterDemo {
   public static void main(String[] args) {
      Formatter formatter1 = new Formatter(Locale.US);
      formatter1.format("Hi My age is %d ",12);
      System.out.println(formatter1 );
      Formatter formatter2 = new Formatter(Locale.JAPAN);
      String s = "Ram";
      formatter2.format("Hi, My Name is %s. ",s);
      System.out.println(formatter2 );
      System.out.println(formatter2.locale() );
   }
}
Output
Hi My age is 12 
Hi, My Name is Ram. 
ja_JP 
POSTED BY
ARVIND RAI
ARVIND RAI
FIND MORE TUTORILAS






©2019 concretepage.com | Privacy Policy | Contact Us