java examples
Home Java Examples Resources Java Interview Questions
Brainpower SEO

How to get all availables Locale's language codes?

When you want to internationalize your application, you need to know the language code and country code. These codes will be used as the properties file name (the file name must be ended in Here is an example that show how to get all supported language's code.

package com.javacoderanch.example.util;

import java.util.Locale;

public class LocaleCountryLanguageCode {
    public static void main(String[] args) {

        // Gets an array of all installed locales. The returned
        // array represents the union of locales supported by the
        // Java runtime environment and by installed
        // LocaleServiceProvider implementations.
        Locale[] locales = Locale.getAvailableLocales();

        StringBuilder sb = new StringBuilder();
        for (Locale locale : locales) {
            sb.append("Locale name: ").append(locale.getDisplayName())
                    .append(" = ")

Here a some of the results produces by the code above:

Locale name: Japanese (Japan) = ja_JP
Locale name: Spanish (Peru) = es_PE
Locale name: English (United States) = en_US
Locale name: French (Belgium) = fr_BE
Locale name: Indonesian (Indonesia) = in_ID
Locale name: German (Germany) = de_DE
Locale name: English (Singapore) = en_SG