Enum Class CountryCode

java.lang.Object
java.lang.Enum<CountryCode>
com.luna.common.i18n.CountryCode
All Implemented Interfaces:
Serializable, Comparable<CountryCode>, java.lang.constant.Constable

public enum CountryCode extends Enum<CountryCode>
ISO 3166-1 country code.

Enum names of this enum themselves are represented by ISO 3166-1 alpha-2 code (2-letter upper-case alphabets). There are instance methods to get the country name (getName()), the ISO 3166-1 alpha-3 code (getAlpha3()) and the ISO 3166-1 numeric code (getNumeric()). In addition, there are static methods to get a CountryCode instance that corresponds to a given alpha-2/alpha-3/numeric code (getByCode(String), getByCode(int)).

 // List all the country codes.
 for (CountryCode code : CountryCode.values())
 {
     // For example, "[US] United States" is printed.
     System.out.format("[%s] %s\n", code, code.getName());
 }

 // Get a CountryCode instance by ISO 3166-1 code.
 CountryCode code = CountryCode.getByCode("JP");

 // Print all the information. Output will be:
 //
 //     Country name            = Japan
 //     ISO 3166-1 alpha-2 code = JP
 //     ISO 3166-1 alpha-3 code = JPN
 //     ISO 3166-1 numeric code = 392
 //     Assignment state        = OFFICIALLY_ASSIGNED
 //
 System.out.println("Country name            = " + code.getName());
 System.out.println("ISO 3166-1 alpha-2 code = " + code.getAlpha2());
 System.out.println("ISO 3166-1 alpha-3 code = " + code.getAlpha3());
 System.out.println("ISO 3166-1 numeric code = " + code.getNumeric());
 System.out.println("Assignment state        = " + code.getAssignment());

 // Convert to a Locale instance.
 Locale locale = code.toLocale();

 // Get a CountryCode by a Locale instance.
 code = CountryCode.getByLocale(locale);

 // Get the currency of the country.
 Currency currency = code.getCurrency();

 // Get a list by a regular expression for names.
 //
 // The list will contain:
 //
 //     CountryCode.AE : United Arab Emirates
 //     CountryCode.GB : United Kingdom
 //     CountryCode.TZ : Tanzania, United Republic of
 //     CountryCode.UK : United Kingdom
 //     CountryCode.UM : United States Minor Outlying Islands
 //     CountryCode.US : United States
 //
 List<CountryCode> list = CountryCode.findByName(".*United.*");

 
 // For backward compatibility for older versions than 1.16, some
 // 4-letter ISO 3166-3 codes are accepted by getByCode(String, boolean)
 // and its variants. To be concrete:
 //
 //     ANHH : CountryCode.AN
 //     BUMM : CountryCode.BU
 //     CSXX : CountryCode.CS
 //     NTHH : CountryCode.NT
 //     TPTL : CountryCode.TP
 //     YUCS : CountryCode.YU
 //     ZRCD : CountryCode.ZR
 //
 code = CountryCode.getByCode("ANHH");
 
Author:
Takahiko Kawasaki