Languages
[Edit]
EN

Java - list of ISO 3166 country codes

6 points
Created by:
Kate_C
21580

In this article, we would like to present simple Java version of countries and associated codes to them described by ISO 3166.

Note: the below list:

Country list as CountryNameEnum.java file:

package example;

import java.util.HashMap;
import java.util.Map;

public enum CountryNameEnum {

	AF("Afghanistan", "AF"),
	AX("├ůland Islands", "AX"),
	AL("Albania", "AL"),
	DZ("Algeria", "DZ"),
	AS("American Samoa", "AS"),
	AD("Andorra", "AD"),
	AO("Angola", "AO"),
	AI("Anguilla", "AI"),
	AQ("Antarctica", "AQ"),
	AG("Antigua and Barbuda", "AG"),
	AR("Argentina", "AR"),
	AM("Armenia", "AM"),
	AW("Aruba", "AW"),
	AU("Australia", "AU"),
	AT("Austria", "AT"),
	AZ("Azerbaijan", "AZ"),
	BS("Bahamas", "BS"),
	BH("Bahrain", "BH"),
	BD("Bangladesh", "BD"),
	BB("Barbados", "BB"),
	BY("Belarus", "BY"),
	BE("Belgium", "BE"),
	BZ("Belize", "BZ"),
	BJ("Benin", "BJ"),
	BM("Bermuda", "BM"),
	BT("Bhutan", "BT"),
	BO("Bolivia (Plurinational State of)", "BO"),
	BQ("Bonaire, Sint Eustatius and Saba", "BQ"),
	BA("Bosnia and Herzegovina", "BA"),
	BW("Botswana", "BW"),
	BV("Bouvet Island", "BV"),
	BR("Brazil", "BR"),
	IO("British Indian Ocean Territory", "IO"),
	BN("Brunei Darussalam", "BN"),
	BG("Bulgaria", "BG"),
	BF("Burkina Faso", "BF"),
	BI("Burundi", "BI"),
	CV("Cabo Verde", "CV"),
	KH("Cambodia", "KH"),
	CM("Cameroon", "CM"),
	CA("Canada", "CA"),
	KY("Cayman Islands", "KY"),
	CF("Central African Republic", "CF"),
	TD("Chad", "TD"),
	CL("Chile", "CL"),
	CN("China", "CN"),
	CX("Christmas Island", "CX"),
	CC("Cocos (Keeling) Islands", "CC"),
	CO("Colombia", "CO"),
	KM("Comoros", "KM"),
	CG("Congo", "CG"),
	CD("Congo (Democratic Republic of the)", "CD"),
	CK("Cook Islands", "CK"),
	CR("Costa Rica", "CR"),
	CI("C├┤te d'Ivoire", "CI"),
	HR("Croatia", "HR"),
	CU("Cuba", "CU"),
	CW("Cura├žao", "CW"),
	CY("Cyprus", "CY"),
	CZ("Czech Republic", "CZ"),
	DK("Denmark", "DK"),
	DJ("Djibouti", "DJ"),
	DM("Dominica", "DM"),
	DO("Dominican Republic", "DO"),
	EC("Ecuador", "EC"),
	EG("Egypt", "EG"),
	SV("El Salvador", "SV"),
	GQ("Equatorial Guinea", "GQ"),
	ER("Eritrea", "ER"),
	EE("Estonia", "EE"),
	ET("Ethiopia", "ET"),
	FK("Falkland Islands (Malvinas)", "FK"),
	FO("Faroe Islands", "FO"),
	FJ("Fiji (Republic of)", "FJ"),
	FI("Finland", "FI"),
	FR("France", "FR"),
	GF("French Guiana", "GF"),
	PF("French Polynesia", "PF"),
	TF("French Southern Territories", "TF"),
	GA("Gabon", "GA"),
	GM("Gambia", "GM"),
	GE("Georgia", "GE"),
	DE("Germany", "DE"),
	GH("Ghana", "GH"),
	GI("Gibraltar", "GI"),
	GR("Greece", "GR"),
	GL("Greenland", "GL"),
	GD("Grenada", "GD"),
	GP("Guadeloupe", "GP"),
	GU("Guam", "GU"),
	GT("Guatemala", "GT"),
	GG("Guernsey", "GG"),
	GN("Guinea", "GN"),
	GW("Guinea-Bissau", "GW"),
	GY("Guyana", "GY"),
	HT("Haiti", "HT"),
	HM("Heard Island and McDonald Islands", "HM"),
	VA("Holy See", "VA"),
	HN("Honduras", "HN"),
	HK("Hong Kong", "HK"),
	HU("Hungary", "HU"),
	IS("Iceland", "IS"),
	IN("India", "IN"),
	ID("Indonesia", "ID"),
	IR("Iran (Islamic Republic of)", "IR"),
	IQ("Iraq", "IQ"),
	IE("Ireland", "IE"),
	IM("Isle of Man", "IM"),
	IL("Israel", "IL"),
	IT("Italy", "IT"),
	JM("Jamaica", "JM"),
	JP("Japan", "JP"),
	JE("Jersey", "JE"),
	JO("Jordan", "JO"),
	KZ("Kazakhstan", "KZ"),
	KE("Kenya", "KE"),
	KI("Kiribati", "KI"),
	KP("Korea (Democratic People's Republic of)", "KP"),
	KR("Korea (Republic of)", "KR"),
	KW("Kuwait", "KW"),
	KG("Kyrgyzstan", "KG"),
	LA("Lao People's Democratic Republic", "LA"),
	LV("Latvia", "LV"),
	LB("Lebanon", "LB"),
	LS("Lesotho", "LS"),
	LR("Liberia", "LR"),
	LY("Libya", "LY"),
	LI("Liechtenstein", "LI"),
	LT("Lithuania", "LT"),
	LU("Luxembourg", "LU"),
	MO("Macao", "MO"),
	MK("Macedonia (the former Yugoslav Republic of)", "MK"),
	MG("Madagascar", "MG"),
	MW("Malawi", "MW"),
	MY("Malaysia", "MY"),
	MV("Maldives", "MV"),
	ML("Mali", "ML"),
	MT("Malta", "MT"),
	MH("Marshall Islands", "MH"),
	MQ("Martinique", "MQ"),
	MR("Mauritania", "MR"),
	MU("Mauritius", "MU"),
	YT("Mayotte", "YT"),
	MX("Mexico", "MX"),
	FM("Micronesia (Federated States of)", "FM"),
	MD("Moldova (Republic of)", "MD"),
	MC("Monaco", "MC"),
	MN("Mongolia", "MN"),
	ME("Montenegro", "ME"),
	MS("Montserrat", "MS"),
	MA("Morocco", "MA"),
	MZ("Mozambique", "MZ"),
	MM("Myanmar", "MM"),
	NA("Namibia", "NA"),
	NR("Nauru", "NR"),
	NP("Nepal", "NP"),
	NL("Netherlands", "NL"),
	NC("New Caledonia", "NC"),
	NZ("New Zealand", "NZ"),
	NI("Nicaragua", "NI"),
	NE("Niger", "NE"),
	NG("Nigeria", "NG"),
	NU("Niue", "NU"),
	NF("Norfolk Island", "NF"),
	MP("Northern Mariana Islands", "MP"),
	NO("Norway", "NO"),
	OM("Oman", "OM"),
	PK("Pakistan", "PK"),
	PW("Palau", "PW"),
	PS("Palestine, State of", "PS"),
	PA("Panama", "PA"),
	PG("Papua New Guinea", "PG"),
	PY("Paraguay", "PY"),
	PE("Peru", "PE"),
	PH("Philippines", "PH"),
	PN("Pitcairn", "PN"),
	PL("Poland", "PL"),
	PT("Portugal", "PT"),
	PR("Puerto Rico", "PR"),
	QA("Qatar", "QA"),
	RE("R├ęunion", "RE"),
	RO("Romania", "RO"),
	RU("Russian Federation", "RU"),
	RW("Rwanda", "RW"),
	BL("Saint Barth├ęlemy", "BL"),
	SH("Saint Helena, Ascension and Tristan da Cunha", "SH"),
	KN("Saint Kitts and Nevis", "KN"),
	LC("Saint Lucia", "LC"),
	MF("Saint Martin (French part)", "MF"),
	PM("Saint Pierre and Miquelon", "PM"),
	VC("Saint Vincent and the Grenadines", "VC"),
	WS("Samoa", "WS"),
	SM("San Marino", "SM"),
	ST("Sao Tome and Principe", "ST"),
	SA("Saudi Arabia", "SA"),
	SN("Senegal", "SN"),
	RS("Serbia", "RS"),
	SC("Seychelles", "SC"),
	SL("Sierra Leone", "SL"),
	SG("Singapore", "SG"),
	SX("Sint Maarten (Dutch part)", "SX"),
	SK("Slovakia", "SK"),
	SI("Slovenia", "SI"),
	SB("Solomon Islands", "SB"),
	SO("Somalia", "SO"),
	ZA("South Africa", "ZA"),
	GS("South Georgia and the South Sandwich Islands", "GS"),
	SS("South Sudan", "SS"),
	ES("Spain", "ES"),
	LK("Sri Lanka", "LK"),
	SD("Sudan", "SD"),
	SR("Suriname", "SR"),
	SJ("Svalbard and Jan Mayen", "SJ"),
	SZ("Swaziland", "SZ"),
	SE("Sweden", "SE"),
	CH("Switzerland", "CH"),
	SY("Syrian Arab Republic", "SY"),
	TW("Taiwan, Province of China", "TW"),
	TJ("Tajikistan", "TJ"),
	TZ("Tanzania, United Republic of", "TZ"),
	TH("Thailand", "TH"),
	TL("Timor-Leste", "TL"),
	TG("Togo", "TG"),
	TK("Tokelau", "TK"),
	TO("Tonga", "TO"),
	TT("Trinidad and Tobago", "TT"),
	TN("Tunisia", "TN"),
	TR("Turkey", "TR"),
	TM("Turkmenistan", "TM"),
	TC("Turks and Caicos Islands", "TC"),
	TV("Tuvalu", "TV"),
	UG("Uganda", "UG"),
	UA("Ukraine", "UA"),
	AE("United Arab Emirates", "AE"),
	GB("United Kingdom of Great Britain and Northern Ireland", "GB"),
	US("United States of America", "US"),
	UM("United States Minor Outlying Islands", "UM"),
	UY("Uruguay", "UY"),
	UZ("Uzbekistan", "UZ"),
	VU("Vanuatu", "VU"),
	VE("Venezuela (Bolivarian Republic of)", "VE"),
	VN("Vietnam", "VN"),
	VG("Virgin Islands (British)", "VG"),
	VI("Virgin Islands (U.S.)", "VI"),
	WF("Wallis and Futuna", "WF"),
	EH("Western Sahara", "EH"),
	YE("Yemen", "YE"),
	ZM("Zambia", "ZM"),
	ZW("Zimbabwe", "ZW");

    private static final Map<String, CountryNameEnum> nameMap = new HashMap<>();
    private static final Map<String, CountryNameEnum> codeMap = new HashMap<>();

    private String name;
    private String code;

    static {
        for (CountryNameEnum el : values()) {
            nameMap.put(el.name, el);
            codeMap.put(el.code, el);
        }
    }

    CountryNameEnum(String name, String code) {
        this.name = name;
        this.code = code;
    }

    public String getName() {
        return this.name;
    }

    public String getCode() {
        return this.code;
    }

    public static CountryNameEnum findByName(String name) {
        return nameMap.get(name);
    }

    public static CountryNameEnum findByCode(String code) {
        return codeMap.get(code);
    }
}

Usage example as Program.java file:

package example;

public class Program {

    public static void main(String[] args) {

        CountryNameEnum pl = CountryNameEnum.findByCode("PL");
        CountryNameEnum gb = CountryNameEnum.findByCode("GB");
        CountryNameEnum us = CountryNameEnum.findByCode("US");
        CountryNameEnum jp = CountryNameEnum.findByCode("JP");

        System.out.println(pl.getName()); // Poland
        System.out.println(gb.getName()); // United Kingdom of Great Britain and Northern Ireland
        System.out.println(us.getName()); // United States of America
        System.out.println(jp.getName()); // Japan
    }
}
Native Advertising
­čÜÇ
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

ÔŁĄ´ŞĆ­čĺ╗ ­čÖé

Join