Does anyone know of a freely available java 1.5 package that provides a list of ISO 3166-1 country codes as a enum or EnumMap? Specifically I need the "ISO 3166-1-alpha-2 code elements", i.e. the 2 character country code like "us", "uk", "de", etc. Creating one is simple enough (although tedious), but if there's a standard one already out there in apache land or the like it would save a little time.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
If anyone is already using the Amazon AWS SDK it includes
com.amazonaws.services.route53domains.model.CountryCode
. I know this is not ideal but it's an alternative if you already use the AWS SDK. For most cases I would use Takahiko'snv-i18n
since, as he mentions, it implements ISO 3166-1.I have created an enum, which you address by the english country name. See country-util.
On each enum you can call
getLocale()
to get the Java Locale.From the Locale you can get all the information you are used to, fx the ISO-3166-1 two letter country code.
Pro:
Con:
This code gets 242 countries in Sun Java 6:
Though the ISO website claims there are 249 ISO 3166-1-alpha-2 code elements, though the javadoc links to the same information.
If you are already going to rely on Java locale, then I suggest using a simple HashMap instead of creating new classes for countries etc.
Here's how I would use it if I were to rely on the Java Localization only:
After you fill the map, you can get the ISO code from the country name whenever you need it. Or you can make it a ISO code to Country name map as well, just modify the 'put' method accordingly.