The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.util  [50 examples]

e335. Listing All Available Locales

    Locale[] locales = Locale.getAvailableLocales();
    
    for (int i=0; i<locales.length; i++) {
        // Get the 2-letter language code
        String language = locales[i].getLanguage();
    
        // Get the 2-letter country code; may be equal to ""
        String country = locales[i].getCountry();
    
        // Get localized name suitable for display to the user
        String locName = locales[i].getDisplayName();
    }
Here's a sample of output using a default locale of Locale.ENGLISH:
    Language Code, Country Code, Localized Name
    ar, , Arabic
    ar, AE, Arabic (United Arab Emirates)
    ar, BH, Arabic (Bahrain)
    ar, DZ, Arabic (Algeria)
    ar, EG, Arabic (Egypt)
    ar, IQ, Arabic (Iraq)
    ar, JO, Arabic (Jordan)
    ar, KW, Arabic (Kuwait)
    ar, LB, Arabic (Lebanon)
Here's a sample of output using a default locale of Locale.FRENCH:
    Language Code, Country Code, Localized Name
    ar, , arabe
    ar, AE, arabe (Emirats Arabes Unis)
    ar, EG, arabe (Egypte)
    ar, IQ, arabe (Irak)
    ar, JO, arabe (Jordanie)
    ar, KW, arabe (Koweit)
    ar, LB, arabe (Liban)

 Related Examples
e331. Generating a Random Number
e332. Breaking a String into Words
e333. Creating a Custom Event
e334. Implementing a Simple Event Notifier
e336. Setting the Default Locale
e337. Associating a Value with an Object

See also: Arrays    Bits    Collections    Dates    Hash Tables    Lists    Property Files    Sets    Sorted Collections    Time    Timers   


© 2002 Addison-Wesley.