是否有 ISO 3166-1 国家代码的开源 Java 枚举

有谁知道一个免费提供的 java 1.5 包,它以枚举或 EnumMap 的形式提供 ISO 3166-1 国家代码列表?具体来说,我需要ISO 3166-1-alpha-2 代码元素",即 2 个字符的国家/地区代码,例如us"、uk"、de"等.创建一个很简单(虽然很乏味),但是如果在 apache 领域或类似的地方已经有一个标准的,它会节省一点时间.

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.

推荐答案

现在实现了国家代码 (ISO 3166-1 alpha-2/alpha-3/numeric) 列表作为 Java 枚举在 GitHub 上可用 Apache 许可证版本 2.0.

Now an implementation of country code (ISO 3166-1 alpha-2/alpha-3/numeric) list as Java enum is available at GitHub under Apache License version 2.0.

示例:

CountryCode cc = CountryCode.getByCode("JP");

System.out.println("Country name = " + cc.getName());                // "Japan"
System.out.println("ISO 3166-1 alpha-2 code = " + cc.getAlpha2());   // "JP"
System.out.println("ISO 3166-1 alpha-3 code = " + cc.getAlpha3());   // "JPN"
System.out.println("ISO 3166-1 numeric code = " + cc.getNumeric());  // 392

<小时>

上次编辑 2016 年 6 月 9 日


Last Edit 2016-Jun-09

CountryCode 枚举与其他 Java 枚举、LanguageCode (ISO 639- 一起打包到 com.neovisionaries.i18n1)、LanguageAlpha3Code (ISO 639-2)、LocaleCode、ScriptCode (ISO 15924) 和 CurrencyCode (ISO 4217) 并注册到 Maven 中央存储库.

CountryCode enum was packaged into com.neovisionaries.i18n with other Java enums, LanguageCode (ISO 639-1), LanguageAlpha3Code (ISO 639-2), LocaleCode, ScriptCode (ISO 15924) and CurrencyCode (ISO 4217) and registered into the Maven Central Repository.

Maven

<dependency>
  <groupId>com.neovisionaries</groupId>
  <artifactId>nv-i18n</artifactId>
  <version>1.22</version>
</dependency>

Gradle

dependencies {
  compile 'com.neovisionaries:nv-i18n:1.22'
}

GitHub

https://github.com/TakahikoKawasaki/nv-i18n

Javadoc

http://takahikokawasaki.github.com/nv-i18n/

OSGi

Bundle-SymbolicName: com.neovisionaries.i18n
Export-Package: com.neovisionaries.i18n;version="1.22.0"

相关文章