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.
Get Java Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.