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?
views:
1019answers:
3
+1
A:
- Create a Map out of this page http://www.theodora.com/country_digraphs.html
- Save it to a file (I suggest XMLEncoder/XMLDecoder class)
- 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.
- Repeat (or use a bi-directional map) these steps for each column of the table on the afore mentioned webpage.
- Fancy-Time: Throw in some code to wrap the entries in a Reference object (SoftReference?) so that the Map won't throw MemoryErrors
KitsuneYMG
2009-04-03 01:58:48
+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.