Skip to Main Content
Java Cookbook
book

Java Cookbook

by Ian F. Darwin
June 2001
Intermediate to advanced content levelIntermediate to advanced
888 pages
21h 1m
English
O'Reilly Media, Inc.
Content preview from Java Cookbook

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.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Practical Cloud-Native Java Development with MicroProfile

Practical Cloud-Native Java Development with MicroProfile

Emily Jiang, Andrew McCright, John Alcorn, David Chan, Alasdair Nottingham
Distributed Computing in Java 9

Distributed Computing in Java 9

Raja Malleswara Rao Malleswara Rao Pattamsetti

Publisher Resources

ISBN: 0596001703Supplemental ContentCatalog PageErrata