Class Locale

java.lang.Object
java.util.Locale

public class Locale extends Object

A language, a country and a variant, with the JDK's value semantics: two locales of the same codes are equal, hash alike and print alike (en_US). The codes are normalized as the JDK normalizes them -- the language to lower case, the country to upper case, with an ASCII fold, so a device set to Turkish cannot turn IT into a dotless it.

This runtime carries no locale data beyond the English names of the common languages and countries, so the getDisplay* methods answer in English whatever locale they are asked for, and fall back to the code. A script and extensions are not kept: getScript is always empty.

  • Field Details

    • ENGLISH

      public static final Locale ENGLISH
      English.
    • FRENCH

      public static final Locale FRENCH
      French.
    • GERMAN

      public static final Locale GERMAN
      German.
    • ITALIAN

      public static final Locale ITALIAN
      Italian.
    • JAPANESE

      public static final Locale JAPANESE
      Japanese.
    • KOREAN

      public static final Locale KOREAN
      Korean.
    • CHINESE

      public static final Locale CHINESE
      Chinese.
    • SIMPLIFIED_CHINESE

      public static final Locale SIMPLIFIED_CHINESE
      Chinese as written in China.
    • TRADITIONAL_CHINESE

      public static final Locale TRADITIONAL_CHINESE
      Chinese as written in Taiwan.
    • FRANCE

      public static final Locale FRANCE
      French in France.
    • GERMANY

      public static final Locale GERMANY
      German in Germany.
    • ITALY

      public static final Locale ITALY
      Italian in Italy.
    • JAPAN

      public static final Locale JAPAN
      Japanese in Japan.
    • KOREA

      public static final Locale KOREA
      Korean in Korea.
    • CHINA

      public static final Locale CHINA
      Chinese in China; the same locale as SIMPLIFIED_CHINESE.
    • PRC

      public static final Locale PRC
      Chinese in China; the same locale as SIMPLIFIED_CHINESE.
    • TAIWAN

      public static final Locale TAIWAN
      Chinese in Taiwan; the same locale as TRADITIONAL_CHINESE.
    • UK

      public static final Locale UK
      English in the United Kingdom.
    • US

      public static final Locale US
      English in the United States.
    • CANADA

      public static final Locale CANADA
      English in Canada.
    • CANADA_FRENCH

      public static final Locale CANADA_FRENCH
      French in Canada.
    • ROOT

      public static final Locale ROOT
      The root locale: no language, country or variant.
  • Constructor Details

    • Locale

      public Locale(String language)
      A locale of a language alone.
    • Locale

      public Locale(String language, String country)
      A locale of a language and a country.
    • Locale

      public Locale(String language, String country, String variant)

      A locale of a language, a country and a variant.

      Throws
      • NullPointerException: if any of them is null
  • Method Details

    • of

      public static Locale of(String language)
      new Locale(language).
    • of

      public static Locale of(String language, String country)
      new Locale(language, country).
    • of

      public static Locale of(String language, String country, String variant)
      new Locale(language, country, variant).
    • getDefault

      public static Locale getDefault()
    • setDefault

      public static void setDefault(Locale l)
    • getLanguage

      public String getLanguage()
    • getCountry

      public String getCountry()
    • getVariant

      public String getVariant()
      The variant, or the empty string.
    • getScript

      public String getScript()
      Always empty: this runtime does not keep a script.
    • hasExtensions

      public boolean hasExtensions()
      Whether the locale carries extensions; never, here.
    • stripExtensions

      public Locale stripExtensions()
      The locale without extensions, which is the locale itself here.
    • forLanguageTag

      public static Locale forLanguageTag(String languageTag)
      The locale an IETF BCP 47 language tag names: fr, en-US, zh-Hans-CN. The first subtag is the language, a four letter subtag after it a script (dropped), the next two letter or three digit subtag the country and the subtags after it, five to eight characters or a digit and three more, the variant. A single character subtag starts the extensions, which are dropped. und and the empty tag are the root locale.
    • toLanguageTag

      public String toLanguageTag()
      The IETF BCP 47 tag of the locale: en-US, fr, or und for the root.
    • equals

      public boolean equals(Object obj)
      Whether obj is a locale of the same language, country and variant.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      A hash of the language, country and variant.
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      en_US, fr, en_US_POSIX, or the empty string for the root locale.
      Overrides:
      toString in class Object
    • getDisplayLanguage

      public String getDisplayLanguage()
      The English name of the language, or its code when this runtime has no name for it.
    • getDisplayLanguage

      public String getDisplayLanguage(Locale inLocale)
      As getDisplayLanguage(): names are in English only.
    • getDisplayCountry

      public String getDisplayCountry()
      The English name of the country, or its code when this runtime has no name for it.
    • getDisplayCountry

      public String getDisplayCountry(Locale inLocale)
      As getDisplayCountry(): names are in English only.
    • getDisplayVariant

      public String getDisplayVariant()
      The variant as it is.
    • getDisplayVariant

      public String getDisplayVariant(Locale inLocale)
      As getDisplayVariant().
    • getDisplayScript

      public String getDisplayScript()
      Always empty: this runtime does not keep a script.
    • getDisplayScript

      public String getDisplayScript(Locale inLocale)
      Always empty: this runtime does not keep a script.
    • getDisplayName

      public String getDisplayName()
      English (United States): the language, then the country and the variant in parentheses.
    • getDisplayName

      public String getDisplayName(Locale inLocale)
      As getDisplayName(): names are in English only.
    • getAvailableLocales

      public static Locale[] getAvailableLocales()
      The default locale and the locales this class has constants for.