views:

153

answers:

2

Using Java, you can get the list of ISO2 codes through Locale.getISOCountries() (see this related question http://stackoverflow.com/questions/712231/best-way-to-get-a-list-of-countries-in-java).

However, I would like to have the list of all country names (in English for example) and not the list of ISO2 country codes. How can I do that by programming in Java or Groovy ?

Thank you very much,

Fabien.

+2  A: 

A good example is here How do I get a list of country names?

Shaji
+3  A: 

Using Groovy, this prints a sorted list of country names:

def countries = [] as SortedSet

Locale.availableLocales.displayCountry.each {
  if (it) {
    countries << it
  }
}

println countries

In my locale, this prints

[Albania, Algeria, Argentina, Australia, Austria, Bahrain, ..., Yemen]

You need to use a Set rather than a List because there are multiple locales for some countries, e.g. French Canada and English Canada locales for the country Canada.

Don