Source Code : Create Locale with Locale Builder

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Create Locale with Locale Builder


import java.text.DateFormat;
import java.text.NumberFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Locale.Builder;

public class Test {
  public static void main(String[] args) {
    long SAMPLE_NUMBER = 123456789L;
    Date NOW = new Date();
    String[][] langRegions = { { "fr", "FR" }, { "ja", "JP" }, { "en", "US" } };
    Builder builder = new Builder();
    Locale l = null;
    for (String[] lr : langRegions) {
      builder.clear();
      builder.setLanguage(lr[0]).setRegion(lr[1]);
      l = builder.build();
      displayLocalizedData(l, SAMPLE_NUMBER, NOW);
    }
  }

  static void displayLocalizedData(Locale l, long number, Date date) {
    NumberFormat nf = NumberFormat.getInstance(l);
    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG,
        DateFormat.LONG, l);
    System.out.printf("Locale: %s
Number: %s
Date: %s

",
        l.getDisplayName(), nf.format(number), df.format(date));
  }
}

 

Thank with us