Java Programming Tutorials

Java programming tutorials with many code examples!

Java Locale information

Java Locale information

In this tutorial we’re going to show how to get information from Locale, display it nicely to users and get installed locales in the system.

Default locale

Here we’ll set and get default Locale and print it using its toString() method:

Locale.setDefault(Locale.US);
Locale locale = Locale.getDefault();
System.out.println("Default locale: " + locale);

It produces the following output:

Default locale: en_US

Locale country

Locale locale = Locale.JAPAN;
System.out.printf("country code: %s, name: %s%n",
    locale.getCountry(), locale.getDisplayCountry());

The output is:

country code: JP, name: Japan

Locale language

Locale locale = Locale.JAPAN;
System.out.printf("language: %s, name: %s%n",
    locale.getLanguage(), locale.getDisplayLanguage());

The output is:

language: ja, name: Japanese

Locale display name for users

To display user readable names of Locale use the following code:

Locale locale = Locale.JAPAN;
System.out.println("Name: " + locale.getDisplayName());

It produces language description formatted according to the current locale:

Name: Japanese (Japan)

Available Locales

To get an array of all installed locales use the following:

System.out.println("All installed locales:");
for (Locale locale : Locale.getAvailableLocales()) {
    System.out.println("Name: " + locale.getDisplayName());
}

On my system (Linux) it produces the following list:

All installed locales:
Name:
Name: Arabic (United Arab Emirates)
Name: Arabic (Jordan)
Name: Arabic (Syria)
Name: Croatian (Croatia)
Name: French (Belgium)
Name: Spanish (Panama)
Name: Maltese (Malta)
Name: Spanish (Venezuela)
Name: Bulgarian
Name: Chinese (Taiwan)
Name: Italian
Name: Korean
Name: Ukrainian
Name: Latvian
Name: Danish (Denmark)
Name: Spanish (Puerto Rico)
Name: Vietnamese (Vietnam)
Name: English (United States)
Name: Serbian (Montenegro)
Name: Swedish (Sweden)
Name: Spanish (Bolivia)
Name: English (Singapore)
Name: Arabic (Bahrain)
Name: Portuguese
Name: Arabic (Saudi Arabia)
Name: Slovak
Name: Arabic (Yemen)
Name: Hindi (India)
Name: Irish
Name: English (Malta)
Name: Finnish (Finland)
Name: Estonian
Name: Swedish
Name: Czech
Name: Serbian (Latin,Bosnia and Herzegovina)
Name: Greek
Name: Ukrainian (Ukraine)
Name: Hungarian
Name: French (Switzerland)
Name: Indonesian
Name: Spanish (Argentina)
Name: Arabic (Egypt)
Name: Japanese (Japan,JP)
Name: Spanish (El Salvador)
Name: Portuguese (Brazil)
Name: Belarusian
Name: Icelandic (Iceland)
Name: Czech (Czech Republic)
Name: Spanish
Name: Polish (Poland)
Name: Turkish
Name: Catalan (Spain)
Name: Serbian (Serbia and Montenegro)
Name: Malay (Malaysia)
Name: Croatian
Name: Lithuanian
Name: Spanish (Spain)
Name: Spanish (Colombia)
Name: Bulgarian (Bulgaria)
Name: Albanian
Name: French
Name: Japanese
Name: Serbian (Bosnia and Herzegovina)
Name: Icelandic
Name: Spanish (Paraguay)
Name: German
Name: Spanish (Ecuador)
Name: Spanish (United States)
Name: Arabic (Sudan)
Name: English
Name: Romanian (Romania)
Name: English (Philippines)
Name: Catalan
Name: Arabic (Tunisia)
Name: Serbian (Latin,Montenegro)
Name: Spanish (Guatemala)
Name: Slovenian
Name: Korean (South Korea)
Name: Greek (Cyprus)
Name: Spanish (Mexico)
Name: Russian (Russia)
Name: Spanish (Honduras)
Name: Chinese (Hong Kong)
Name: Norwegian (Norway,Nynorsk)
Name: Hungarian (Hungary)
Name: Thai (Thailand)
Name: Arabic (Iraq)
Name: Spanish (Chile)
Name: Finnish
Name: Arabic (Morocco)
Name: Irish (Ireland)
Name: Macedonian
Name: Turkish (Turkey)
Name: Estonian (Estonia)
Name: Arabic (Qatar)
Name: Serbian (Latin)
Name: Portuguese (Portugal)
Name: French (Luxembourg)
Name: Arabic (Oman)
Name: Thai
Name: Albanian (Albania)
Name: Spanish (Dominican Republic)
Name: Spanish (Cuba)
Name: Arabic
Name: Russian
Name: English (New Zealand)
Name: Serbian (Serbia)
Name: German (Switzerland)
Name: Spanish (Uruguay)
Name: Malay
Name: Greek (Greece)
Name: Hebrew (Israel)
Name: English (South Africa)
Name: Thai (Thailand,TH)
Name: Hindi
Name: French (France)
Name: German (Austria)
Name: Dutch
Name: Norwegian (Norway)
Name: English (Australia)
Name: Vietnamese
Name: Dutch (Netherlands)
Name: French (Canada)
Name: Latvian (Latvia)
Name: German (Luxembourg)
Name: Spanish (Costa Rica)
Name: Arabic (Kuwait)
Name: Serbian
Name: Arabic (Libya)
Name: Maltese
Name: Italian (Switzerland)
Name: Danish
Name: German (Germany)
Name: Arabic (Algeria)
Name: Slovak (Slovakia)
Name: Lithuanian (Lithuania)
Name: Italian (Italy)
Name: English (Ireland)
Name: Chinese (Singapore)
Name: Romanian
Name: English (Canada)
Name: Dutch (Belgium)
Name: Norwegian
Name: Polish
Name: Chinese (China)
Name: Japanese (Japan)
Name: German (Greece)
Name: Serbian (Latin,Serbia)
Name: Hebrew
Name: English (India)
Name: Arabic (Lebanon)
Name: Spanish (Nicaragua)
Name: Chinese
Name: Macedonian (Macedonia)
Name: Belarusian (Belarus)
Name: Slovenian (Slovenia)
Name: Spanish (Peru)
Name: Indonesian (Indonesia)
Name: English (United Kingdom)

References:

Share with the World!