I am trying to get all the locales from the JVM to populate a Country drop down. The first item is an empty not null object. It isn't null because I am using a TreeMap Collection to add the country Abbreviations and (Displayable) Names. Look below to see what the collection is.
{=, AE=United Arab Emirates, AL=Albania, AR=Argentina, AT=Austria, AU=Australia, BA=Bosnia and Herzegovina, BE=Belgium, BG=Bulgaria, BH=Bahrain, BO=Bolivia, BR=Brazil,....
Here's the code. I remove that empty object to make sure the first value is not empty.
public Map<String, String> countries(Locale currentLocale) {
Map<String, String> countries = new TreeMap<String, String>();
for (Locale locale : Locale.getAvailableLocales()) {
countries.put(locale.getCountry(),
locale.getDisplayCountry(currentLocale));
}
countries.remove("");
return countries;
}
JVM version - (build 1.7.0_09-b05)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…