tags:

views:

1019

answers:

3

Other than Locale.getISOCountries() that is, because I'm already getting some strange errors with that. What else is the best way to get the 2-letter country codes as well as the full country name?

+1  A: 
  1. Create a Map out of this page http://www.theodora.com/country_digraphs.html
  2. Save it to a file (I suggest XMLEncoder/XMLDecoder class)
  3. Create a wrapping class that loads this Map from the file (I'd use a lazily initialized singleton) and allows access to the get(...) methods.
  4. Repeat (or use a bi-directional map) these steps for each column of the table on the afore mentioned webpage.
  5. Fancy-Time: Throw in some code to wrap the entries in a Reference object (SoftReference?) so that the Map won't throw MemoryErrors
KitsuneYMG
+1  A: 

For a separate project, I took the country code data from the ISO site.

Beware of the following:

  • The names are in all caps. You will probably want to tweak it so it's not.
  • The names are not all in simple ASCII.
  • The names are not entirely political neutral (it is probably impossible for any purported list of countries to be). E.g., "Taiwan, Province of China" is a name. A good starting point to learn about the issues is this blog post.
+1  A: 

try this: http://www.java2s.com/Code/Java/I18N/Getalistofcountrynames.htm

hope this help!

DK

Duy Khoa