O'Reilly logo

Java Cookbook by Ian F. Darwin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Listing Available Locales

Problem

You want to see what locales are available.

Solution

Call Locale.getAvailableLocales( ).

Discussion

A typical runtime may have dozens of locales available. The program ListLocales uses the method getAvailableLocales( ) and prints the list:

// File ListLocales.java
Locale[] list = Locale.getAvailableLocales(  );
        for (int i=0; i<list.length; i++)
            System.out.println(list[i]);
    }
}

The list is far too long to show here, as you can judge by the first few entries:

> java ListLocales
en
en_US
ar
ar_AE
ar_BH
ar_DZ
ar_EG
ar_IQ
ar_JO
ar_KW
ar_LB
ar_LY
ar_MA
ar_OM
ar_QA
ar_SA
ar_SD
ar_SY
ar_TN
ar_YE
be
be_BY

On my system the complete list has an even dozen dozen (144) locales, as listed by the command java ListLocales | wc -l.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required