Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an open source java enum of ISO 3166-1 country codes

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.

like image 956
Jason Jenkins Avatar asked Sep 26 '08 14:09

Jason Jenkins


People also ask

Does every country have an ISO code?

The ISO country codes are internationally recognized codes that designate every country and most of the dependent areas a two-letter combination or a three-letter combination; it is like an acronym, that stands for a country or a state.

For what does the ISO 3166 provide a standard?

The purpose of ISO 3166 is to define internationally recognized codes of letters and/or numbers that we can use when we refer to countries and their subdivisions.

How many countries are in the ISO standard list?

The ISO 3166-1 standard currently comprises 249 countries, 193 of which are sovereign states that are members of the United Nations.


1 Answers

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.

Example:

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 

Last Edit 2016-Jun-09

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.29</version> </dependency> 

Gradle

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

GitHub

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

Javadoc

https://takahikokawasaki.github.io/nv-i18n/

OSGi

Bundle-SymbolicName: com.neovisionaries.i18n Export-Package: com.neovisionaries.i18n;version="1.28.0" 
like image 133
Takahiko Kawasaki Avatar answered Sep 19 '22 08:09

Takahiko Kawasaki