Java Locale class

Description

Java Locale class

import java.util.Locale;

public class Main {
  public static void main(String[] args) {
    Locale defaultLocale = Locale.getDefault();
    printLocaleDetails(defaultLocale);/*from  w w w  .j  a  va2s.co m*/
    printLocaleDetails(Locale.FRANCE);
    Locale germanLocale = new Locale("de", "DE");
    printLocaleDetails(germanLocale);

  }

  public static void printLocaleDetails(Locale locale) {
    String languageCode = locale.getLanguage();
    String languageName = locale.getDisplayLanguage();
    String countryCode = locale.getCountry();
    String countryName = locale.getDisplayCountry();

    // Print the locale info
    System.out.println(
        "Language: " + languageName + "(" + languageCode + "); " + "Country: " + countryName + "(" + countryCode + ")");
  }

}



PreviousNext

Related