MessageFormat: setLocale(Locale locale) : MessageFormat « java.text « Java by API






MessageFormat: setLocale(Locale locale)

 

import java.text.MessageFormat;
import java.util.Date;
import java.util.Locale;

public class MainClass {

  public static void main(String[] argv) {
    String pattern = "{0}K was deleted on {1}.";
    MessageFormat formatter = new MessageFormat(pattern);

    Double kb = new Double(3.5);
    Date today = new Date();
    Object[] arguments = { kb, today };

    formatter.setLocale(Locale.US);
    System.out.println(formatter.format(arguments));

    formatter.setLocale(Locale.FRANCE);
    System.out.println(formatter.format(arguments));

    pattern = "On {1}, {0}K was deleted.";
    formatter.applyPattern(pattern);
    System.out.println(formatter.format(arguments));

    formatter.setLocale(Locale.US);
    System.out.println(formatter.format(arguments));
  }
}
           
         
  








Related examples in the same category

1.new MessageFormat(String pattern)
2.MessageFormat: format(String pattern, Object... arguments)