There are several constructors for the locale class:
Locale (String language)
Locale (String language, String country)
Locale (String language, String country, string variant)
The following is an instantiation of a locale object by constructing a method:
1 Public classLocaletest {2 Public Static voidMain (string[] args) {3 4 //Create a common English locale.5Locale Locale11 =NewLocale ("en"));6 //Create a locale for Canadian English.7Locale locale12 =NewLocale ("en", "CA");8 //Create an American English locale, the English language of Silicon Valley9Locale locale13 =NewLocale ("en", "US", "Siliconvalley"));Ten One } A}
The locale class has some predefined instances of locale objects:
Locale Name Locale
=======================================
Locale.china ZH_CN
Locale.chinese en
Locale.simplified_chinese ZH_CN
Locale.traditional_chinese ZH_TW
LOCALE.PRC ZH_CN
Locale.english en
locale.uk EN_GB
Locale.us en_US
Locale.france fr_fr
Locale.french FR
The following example is a German locale instance in English (which is the author's host by default), and German and French provide information:
1 Public classLocaletest {2 3 Public Static voidMain (string[] args) {4Locale Delocale =NewLocale ("de", "de");5Locale Frlocale =NewLocale ("fr", "fr");6SYSTEM.OUT.PRINTLN ("Default language name (default):"7+delocale.getdisplaylanguage ());8System.out.println ("German language name (German):"9+delocale.getdisplaylanguage (Delocale));TenSystem.out.println ("German language name (French):" One+delocale.getdisplaylanguage (Frlocale)); A } - -}
The output is:
Default language name (default): German
German language Name (German): Deutsch
German language Name (French): allemand
Internationalization: The locale class under the Java platform