Java Cookbook
Get all ISO language and country codes
Problem:
You want to retrieve all ISO639 language codes or ISO3166 region codes.
Solution:
You can retrieve both ISO 639 language codes and ISO 3166 country codes by calling static methods on the Locale class.
To retrieve the ISO 639 language codes:
String[] locales = Locale.getISOLanguages();
for(int x = 0; x < locales.length; x++){
System.out.println(locales[x]);
}
To retrieve the ISO 3166 country codes:
String[] locales = Locale.getISOCountries();
for(int x = 0; x < locales.length; x++){
System.out.println(locales[x]);
}
If you are testing any of these recipes in Eclipse and the characters are not displaying correctly in your console visit http://i18ncookbook.com/eclipse_settings.
This site is ad supported. I hope you find something among our sponsors worth clicking. ;)
i18n search