public enum CountryCode extends Enum<CountryCode>
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");
Modifier and Type | Class and Description |
---|---|
static class |
CountryCode.Assignment
Code assignment state in ISO 3166-1.
|
Enum Constant and Description |
---|
AC
Ascension Island
[AC, ASC, -1,
Exceptionally reserved]
|
AD
|
AE
United Arab Emirates
[AE, AE, 784,
Officially assigned]
|
AF
Afghanistan
[AF, AFG, 4,
Officially assigned]
|
AG
Antigua and Barbuda
[AG, ATG, 28,
Officially assigned]
|
AI
|
AL
|
AM
|
AN
Netherlands Antilles
[AN, ANT, 530,
Traditionally reserved]
|
AO
|
AQ
Antarctica
[AQ, ATA, 10,
Officially assigned]
|
AR
|
AS
American Samoa
[AS, ASM, 16,
Officially assigned]
|
AT
|
AU
|
AW
|
AX
Åland Islands
[AX, ALA, 248,
Officially assigned]
|
AZ
Azerbaijan
[AZ, AZE, 31,
Officially assigned]
|
BA
Bosnia and Herzegovina
[BA, BIH, 70,
Officially assigned]
|
BB
|
BD
Bangladesh
[BD, BGD, 50,
Officially assigned]
|
BE
|
BF
Burkina Faso
[BF, BFA, 854,
Officially assigned]
|
BG
|
BH
|
BI
|
BJ
|
BL
Saint Barthélemy
[BL, BLM, 652,
Officially assigned]
|
BM
|
BN
Brunei Darussalam
[BN, BRN, 96,
Officially assigned]
|
BO
Bolivia, Plurinational State of
[BO, BOL, 68,
Officially assigned]
|
BQ
Bonaire, Sint Eustatius and Saba
[BQ, BES, 535,
Officially assigned]
|
BR
|
BS
|
BT
|
BU
|
BV
Bouvet Island
[BV, BVT, 74,
Officially assigned]
|
BW
|
BY
|
BZ
|
CA
|
CC
Cocos (Keeling) Islands
[CC, CCK, 166,
Officially assigned]
|
CD
Congo, the Democratic Republic of the
[CD, COD, 180,
Officially assigned]
|
CF
Central African Republic
[CF, CAF, 140,
Officially assigned]
|
CG
|
CH
Switzerland
[CH, CHE, 756,
Officially assigned]
|
CI
Côte d'Ivoire
[CI, CIV, 384,
Officially assigned]
|
CK
Cook Islands
[CK, COK, 184,
Officially assigned]
|
CL
|
CM
|
CN
|
CO
|
CP
Clipperton Island
[CP, CPT, -1,
Exceptionally reserved]
|
CR
Costa Rica
[CR, CRI, 188,
Officially assigned]
|
CS
Serbia and Montenegro
[CS, SCG, 891,
Traditionally reserved]
|
CU
|
CV
Cape Verde
[CV, CPV, 132,
Officially assigned]
|
CW
|
CX
Christmas Island
[CX, CXR, 162,
Officially assigned]
|
CY
|
CZ
Czech Republic
[CZ, CZE, 203,
Officially assigned]
|
DE
|
DG
Diego Garcia
[DG, DGA, -1,
Exceptionally reserved]
|
DJ
|
DK
|
DM
|
DO
Dominican Republic
[DO, DOM, 214,
Officially assigned]
|
DZ
|
EA
|
EC
|
EE
|
EG
|
EH
Western Sahara
[EH, ESH, 732,
Officially assigned]
|
ER
|
ES
|
ET
|
EU
European Union
[EU, null, -1,
Exceptionally reserved]
|
EZ
|
FI
|
FJ
|
FK
Falkland Islands (Malvinas)
[FK, FLK, 238,
Officially assigned]
|
FM
Micronesia, Federated States of
[FM, FSM, 583,
Officially assigned]
|
FO
Faroe Islands
[FO, FRO, 234,
Officially assigned]
|
FR
|
FX
France, Metropolitan
[FX, FXX, 249,
Exceptionally reserved]
|
GA
|
GB
United Kingdom
[GB, GBR, 826,
Officially assigned]
|
GD
|
GE
|
GF
French Guiana
[GF, GUF, 254,
Officially assigned]
|
GG
|
GH
|
GI
|
GL
|
GM
|
GN
|
GP
Guadeloupe
[GP, GLP, 312,
Officially assigned]
|
GQ
Equatorial Guinea
[GQ, GNQ, 226,
Officially assigned]
|
GR
|
GS
South Georgia and the South Sandwich Islands
[GS, SGS, 239,
Officially assigned]
|
GT
|
GU
|
GW
Guinea-Bissau
[GW, GNB, 624,
Officially assigned]
|
GY
|
HK
|
HM
Heard Island and McDonald Islands
[HM, HMD, 334,
Officially assigned]
|
HN
|
HR
|
HT
|
HU
|
IC
Canary Islands
[IC, null, -1,
Exceptionally reserved]
|
ID
|
IE
|
IL
|
IM
Isle of Man
[IM, IMN, 833,
Officially assigned]
|
IN
|
IO
British Indian Ocean Territory
[IO, IOT, 86,
Officially assigned]
|
IQ
|
IR
Iran, Islamic Republic of
[IR, IRN, 364,
Officially assigned]
|
IS
|
IT
|
JE
|
JM
|
JO
|
JP
|
KE
|
KG
Kyrgyzstan
[KG, KGZ, 417,
Officially assigned]
|
KH
|
KI
|
KM
|
KN
Saint Kitts and Nevis
[KN, KNA, 659,
Officially assigned]
|
KP
Korea, Democratic People's Republic of
[KP, PRK, 408,
Officially assigned]
|
KR
Korea, Republic of
[KR, KOR, 410,
Officially assigned]
|
KW
|
KY
Cayman Islands
[KY, CYM, 136,
Officially assigned]
|
KZ
Kazakhstan
[KZ, KAZ, 398,
Officially assigned]
|
LA
Lao People's Democratic Republic
[LA, LAO, 418,
Officially assigned]
|
LB
|
LC
Saint Lucia
[LC, LCA, 662,
Officially assigned]
|
LI
Liechtenstein
[LI, LIE, 438,
Officially assigned]
|
LK
|
LR
|
LS
|
LT
|
LU
Luxembourg
[LU, LUX, 442,
Officially assigned]
|
LV
|
LY
|
MA
|
MC
|
MD
Moldova, Republic of
[MD, MDA, 498,
Officially assigned]
|
ME
Montenegro
[ME, MNE, 499,
Officially assigned]
|
MF
Saint Martin (French part)
[MF, MAF, 663,
Officially assigned]
|
MG
Madagascar
[MG, MDG, 450,
Officially assigned]
|
MH
Marshall Islands
[MH, MHL, 584,
Officially assigned]
|
MK
North Macedonia, Republic of
[MK, MKD, 807,
Officially assigned]
|
ML
|
MM
|
MN
|
MO
|
MP
Northern Mariana Islands
[MP, MNP, 580,
Officially assigned]
|
MQ
Martinique
[MQ, MTQ, 474,
Officially assigned]
|
MR
Mauritania
[MR, MRT, 478,
Officially assigned]
|
MS
Montserrat
[MS, MSR, 500,
Officially assigned]
|
MT
|
MU
|
MV
|
MW
|
MX
|
MY
|
MZ
Mozambique
[MZ, MOZ, 508,
Officially assigned]
|
NA
|
NC
New Caledonia
[NC, NCL, 540,
Officially assigned]
|
NE
|
NF
Norfolk Island
[NF, NFK, 574,
Officially assigned]
|
NG
|
NI
|
NL
Netherlands
[NL, NLD, 528,
Officially assigned]
|
NO
|
NP
|
NR
|
NT
Neutral Zone
[NT, NTZ, 536,
Traditionally reserved]
|
NU
|
NZ
New Zealand
[NZ, NZL, 554,
Officially assigned]
|
OM
|
PA
|
PE
|
PF
French Polynesia
[PF, PYF, 258,
Officially assigned]
|
PG
Papua New Guinea
[PG, PNG, 598,
Officially assigned]
|
PH
Philippines
[PH, PHL, 608,
Officially assigned]
|
PK
|
PL
|
PM
Saint Pierre and Miquelon
[PM, SPM, 666,
Officially assigned]
|
PN
|
PR
Puerto Rico
[PR, PRI, 630,
Officially assigned]
|
PS
Palestine, State of
[PS, PSE, 275,
Officially assigned]
|
PT
|
PW
|
PY
|
QA
|
RE
|
RO
|
RS
|
RU
Russian Federation
[RU, RUS, 643,
Officially assigned]
|
RW
|
SA
Saudi Arabia
[SA, SAU, 682,
Officially assigned]
|
SB
Solomon Islands
[SB, SLB, 90,
Officially assigned]
|
SC
Seychelles
[SC, SYC, 690,
Officially assigned]
|
SD
|
SE
|
SF
|
SG
|
SH
Saint Helena, Ascension and Tristan da Cunha
[SH, SHN, 654,
Officially assigned]
|
SI
|
SJ
Svalbard and Jan Mayen
[SJ, SJM, 744,
Officially assigned]
|
SK
|
SL
Sierra Leone
[SL, SLE, 694,
Officially assigned]
|
SM
San Marino
[SM, SMR, 674,
Officially assigned]
|
SN
|
SO
|
SR
|
SS
South Sudan
[SS, SSD, 728,
Officially assigned]
|
ST
Sao Tome and Principe
[ST, STP, 678,
Officially assigned]
|
SU
|
SV
El Salvador
[SV, SLV, 222,
Officially assigned]
|
SX
Sint Maarten (Dutch part)
[SX, SXM, 534,
Officially assigned]
|
SY
Syrian Arab Republic
[SY, SYR, 760,
Officially assigned]
|
SZ
|
TA
Tristan da Cunha
[TA, TAA, -1,
Exceptionally reserved.
|
TC
Turks and Caicos Islands
[TC, TCA, 796,
Officially assigned]
|
TD
|
TF
French Southern Territories
[TF, ATF, 260,
Officially assigned]
|
TG
|
TH
|
TJ
Tajikistan
[TJ, TJK, 762,
Officially assigned]
|
TK
|
TL
Timor-Leste
[TL, TLS, 626,
Officially assigned]
|
TM
Turkmenistan
[TM, TKM, 795,
Officially assigned]
|
TN
|
TO
|
TP
East Timor
[TP, TMP, 626,
Traditionally reserved]
|
TR
|
TT
Trinidad and Tobago
[TT, TTO, 780,
Officially assigned]
|
TV
|
TW
Taiwan, Province of China
[TW, TWN, 158,
Officially assigned]
|
TZ
Tanzania, United Republic of
[TZ, TZA, 834,
Officially assigned]
|
UA
|
UG
|
UK
United Kingdom
[UK, null, 826,
Exceptionally reserved]
|
UM
United States Minor Outlying Islands
[UM, UMI, 581,
Officially assigned]
|
UNDEFINED
Undefined [UNDEFINED, null, -1, User assigned]
|
US
United States
[US, USA, 840,
Officially assigned]
|
UY
|
UZ
Uzbekistan
[UZ, UZB, 860,
Officially assigned]
|
VA
Holy See (Vatican City State)
[VA, VAT, 336,
Officially assigned]
|
VC
Saint Vincent and the Grenadines
[VC, VCT, 670,
Officially assigned]
|
VE
Venezuela, Bolivarian Republic of
[VE, VEN, 862,
Officially assigned]
|
VG
Virgin Islands, British
[VG, VGB, 92,
Officially assigned]
|
VI
Virgin Islands, U.S.
[VI, VIR, 850,
Officially assigned]
|
VN
|
VU
|
WF
Wallis and Futuna
[WF, WLF, 876,
Officially assigned]
|
WS
|
XI
Northern Ireland
[XI, XXI, -1,
User assigned]
|
XK
Kosovo, Republic of
[XK, XXK, -1,
User assigned]
|
XU
United Kingdom (excluding Northern Ireland)
[XU, XXU, -1,
User assigned]
|
YE
|
YT
|
YU
Yugoslavia
[YU, YUG, 890,
Traditionally reserved]
|
ZA
South Africa
[ZA, ZAF, 710,
Officially assigned]
|
ZM
|
ZR
|
ZW
|
Modifier and Type | Method and Description |
---|---|
static List<CountryCode> |
findByName(Pattern pattern)
Get a list of
CountryCode by a name pattern. |
static List<CountryCode> |
findByName(String regex)
Get a list of
CountryCode by a name regular expression. |
String |
getAlpha2()
Get the ISO 3166-1 alpha-2 code.
|
String |
getAlpha3()
Get the ISO 3166-1 alpha-3 code.
|
CountryCode.Assignment |
getAssignment()
Get the assignment state of this country code in ISO 3166-1.
|
static CountryCode |
getByAlpha2Code(String code)
Get a
CountryCode that corresponds to the given ISO 3166-1
alpha-2 code. |
static CountryCode |
getByAlpha3Code(String code)
Get a
CountryCode that corresponds to the given ISO 3166-1
alpha-3 code. |
static CountryCode |
getByAlpha4Code(String code)
Get a
CountryCode that corresponds to the given alpha-4 code. |
static CountryCode |
getByCode(int code)
Get a
CountryCode that corresponds to the given
ISO 3166-1
numeric code. |
static CountryCode |
getByCode(String code)
|
static CountryCode |
getByCode(String code,
boolean caseSensitive)
|
static CountryCode |
getByCodeIgnoreCase(String code)
|
static CountryCode |
getByLocale(Locale locale)
Get a
CountryCode that corresponds to the country code of
the given Locale instance. |
Currency |
getCurrency()
Get the currency.
|
String |
getName()
Get the country name.
|
int |
getNumeric()
Get the ISO 3166-1 numeric code.
|
Locale |
toLocale()
Convert this
CountryCode instance to a Locale instance. |
static CountryCode |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static CountryCode[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final CountryCode UNDEFINED
This is not an official ISO 3166-1 code.
public static final CountryCode AC
public static final CountryCode AD
public static final CountryCode AE
public static final CountryCode AF
public static final CountryCode AG
public static final CountryCode AI
public static final CountryCode AL
public static final CountryCode AM
public static final CountryCode AN
Since version 1.16, the value of alpha-3 code of this entry is ANT
(not ANHH
).
public static final CountryCode AO
public static final CountryCode AQ
public static final CountryCode AR
public static final CountryCode AS
public static final CountryCode AT
public static final CountryCode AU
public static final CountryCode AW
public static final CountryCode AX
The country name was changed from "â„«land Islands" (up to 1.14) to "Ã…land Islands" (since 1.15).
public static final CountryCode AZ
public static final CountryCode BA
public static final CountryCode BB
public static final CountryCode BD
public static final CountryCode BE
public static final CountryCode BF
public static final CountryCode BG
public static final CountryCode BH
public static final CountryCode BI
public static final CountryCode BJ
public static final CountryCode BL
public static final CountryCode BM
public static final CountryCode BN
public static final CountryCode BO
public static final CountryCode BQ
public static final CountryCode BR
public static final CountryCode BS
public static final CountryCode BT
public static final CountryCode BU
Since version 1.16, the value of alpha-3 code of this entry is BUR
(not BUMM
).
MM
public static final CountryCode BV
public static final CountryCode BW
public static final CountryCode BY
public static final CountryCode BZ
public static final CountryCode CA
public static final CountryCode CC
public static final CountryCode CD
ZR
public static final CountryCode CF
public static final CountryCode CG
public static final CountryCode CH
public static final CountryCode CI
public static final CountryCode CK
public static final CountryCode CL
public static final CountryCode CM
public static final CountryCode CN
public static final CountryCode CO
public static final CountryCode CP
public static final CountryCode CR
public static final CountryCode CS
Since version 1.16, the value of alpha-3 code of this entry is SCG
(not CSXX
).
public static final CountryCode CU
public static final CountryCode CV
public static final CountryCode CW
public static final CountryCode CX
public static final CountryCode CY
public static final CountryCode CZ
public static final CountryCode DE
public static final CountryCode DG
public static final CountryCode DJ
public static final CountryCode DK
public static final CountryCode DM
public static final CountryCode DO
public static final CountryCode DZ
public static final CountryCode EA
public static final CountryCode EC
public static final CountryCode EE
public static final CountryCode EG
public static final CountryCode EH
public static final CountryCode ER
public static final CountryCode ES
public static final CountryCode ET
public static final CountryCode EU
public static final CountryCode EZ
public static final CountryCode FI
SF
public static final CountryCode FJ
public static final CountryCode FK
public static final CountryCode FM
public static final CountryCode FO
public static final CountryCode FR
public static final CountryCode FX
Since version 1.17, the numeric code of this entry is 249.
public static final CountryCode GA
public static final CountryCode GB
UK
public static final CountryCode GD
public static final CountryCode GE
public static final CountryCode GF
public static final CountryCode GG
public static final CountryCode GH
public static final CountryCode GI
public static final CountryCode GL
public static final CountryCode GM
public static final CountryCode GN
public static final CountryCode GP
public static final CountryCode GQ
public static final CountryCode GR
public static final CountryCode GS
public static final CountryCode GT
public static final CountryCode GU
public static final CountryCode GW
public static final CountryCode GY
public static final CountryCode HK
public static final CountryCode HM
public static final CountryCode HN
public static final CountryCode HR
public static final CountryCode HT
public static final CountryCode HU
public static final CountryCode IC
public static final CountryCode ID
public static final CountryCode IE
public static final CountryCode IL
public static final CountryCode IM
public static final CountryCode IN
public static final CountryCode IO
public static final CountryCode IQ
public static final CountryCode IR
public static final CountryCode IS
public static final CountryCode IT
public static final CountryCode JE
public static final CountryCode JM
public static final CountryCode JO
public static final CountryCode JP
public static final CountryCode KE
public static final CountryCode KG
public static final CountryCode KH
public static final CountryCode KI
public static final CountryCode KM
public static final CountryCode KN
public static final CountryCode KP
public static final CountryCode KR
public static final CountryCode KW
public static final CountryCode KY
public static final CountryCode KZ
public static final CountryCode LA
public static final CountryCode LB
public static final CountryCode LC
public static final CountryCode LI
public static final CountryCode LK
public static final CountryCode LR
public static final CountryCode LS
public static final CountryCode LT
public static final CountryCode LU
public static final CountryCode LV
public static final CountryCode LY
public static final CountryCode MA
public static final CountryCode MC
public static final CountryCode MD
public static final CountryCode ME
public static final CountryCode MF
public static final CountryCode MG
public static final CountryCode MH
public static final CountryCode MK
public static final CountryCode ML
public static final CountryCode MM
BU
public static final CountryCode MN
public static final CountryCode MO
public static final CountryCode MP
public static final CountryCode MQ
public static final CountryCode MR
public static final CountryCode MS
public static final CountryCode MT
public static final CountryCode MU
public static final CountryCode MV
public static final CountryCode MW
public static final CountryCode MX
public static final CountryCode MY
public static final CountryCode MZ
public static final CountryCode NA
public static final CountryCode NC
public static final CountryCode NE
public static final CountryCode NF
public static final CountryCode NG
public static final CountryCode NI
public static final CountryCode NL
public static final CountryCode NO
public static final CountryCode NP
public static final CountryCode NR
public static final CountryCode NT
Since version 1.16, the value of alpha-3 code of this entry is NTZ
(not NTHH
).
public static final CountryCode NU
public static final CountryCode NZ
public static final CountryCode OM
public static final CountryCode PA
public static final CountryCode PE
public static final CountryCode PF
public static final CountryCode PG
public static final CountryCode PH
public static final CountryCode PK
public static final CountryCode PL
public static final CountryCode PM
public static final CountryCode PN
public static final CountryCode PR
public static final CountryCode PS
public static final CountryCode PT
public static final CountryCode PW
public static final CountryCode PY
public static final CountryCode QA
public static final CountryCode RE
public static final CountryCode RO
public static final CountryCode RS
public static final CountryCode RU
public static final CountryCode RW
public static final CountryCode SA
public static final CountryCode SB
public static final CountryCode SC
public static final CountryCode SD
public static final CountryCode SE
public static final CountryCode SF
FI
public static final CountryCode SG
public static final CountryCode SH
public static final CountryCode SI
public static final CountryCode SJ
public static final CountryCode SK
public static final CountryCode SL
public static final CountryCode SM
public static final CountryCode SN
public static final CountryCode SO
public static final CountryCode SR
public static final CountryCode SS
public static final CountryCode ST
public static final CountryCode SU
public static final CountryCode SV
public static final CountryCode SX
public static final CountryCode SY
public static final CountryCode SZ
public static final CountryCode TA
public static final CountryCode TC
public static final CountryCode TD
public static final CountryCode TF
public static final CountryCode TG
public static final CountryCode TH
public static final CountryCode TJ
public static final CountryCode TK
public static final CountryCode TL
TM
public static final CountryCode TM
public static final CountryCode TN
public static final CountryCode TO
public static final CountryCode TP
Since version 1.16, the value of alpha-3 code of this entry is TMP
(not TPTL
).
Since version 1.17, the numeric code of this entry is 626.
TL
public static final CountryCode TR
public static final CountryCode TT
public static final CountryCode TV
public static final CountryCode TW
public static final CountryCode TZ
public static final CountryCode UA
public static final CountryCode UG
public static final CountryCode UK
Since version 1.17, the numeric code of this entry is 826.
GB
public static final CountryCode UM
public static final CountryCode US
public static final CountryCode UY
public static final CountryCode UZ
public static final CountryCode VA
public static final CountryCode VC
public static final CountryCode VE
public static final CountryCode VG
public static final CountryCode VI
public static final CountryCode VN
public static final CountryCode VU
public static final CountryCode WF
public static final CountryCode WS
public static final CountryCode XI
public static final CountryCode XU
public static final CountryCode XK
public static final CountryCode YE
public static final CountryCode YT
public static final CountryCode YU
Since version 1.16, the value of alpha-3 code of this entry is YUG
(not YUCS
).
public static final CountryCode ZA
public static final CountryCode ZM
public static final CountryCode ZR
Since version 1.16, the value of alpha-3 code of this entry is ZAR
(not ZRCD
).
Since version 1.17, the numeric code of this entry is 180.
CD
public static final CountryCode ZW
public static CountryCode[] values()
for (CountryCode c : CountryCode.values()) System.out.println(c);
public static CountryCode valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullpublic String getName()
public String getAlpha2()
UNDEFINED
returns "UNDEFINED"
which is not an official ISO 3166-1 alpha-2 code.public String getAlpha3()
EU
)
returns null
.
UNDEFINED
returns null
, too.public int getNumeric()
EU
)
returns -1
.
UNDEFINED
returns -1
, too.public CountryCode.Assignment getAssignment()
public Locale toLocale()
CountryCode
instance to a Locale
instance.
In most cases, this method creates a new Locale
instance
every time it is called, but some CountryCode
instances return
their corresponding entries in Locale
class. For example,
CountryCode.CA
always returns Locale.CANADA
.
The table below lists CountryCode
entries whose toLocale()
do not create new Locale instances but return entries in
Locale
class.
In addition, toLocale()
of CountryCode.UNDEFINED
behaves a bit differently. It returns
Locale.ROOT
when it is available (i.e. when
the version of Java SE is 1.6 or higher). Otherwise, it returns
a Locale
instance whose language and country are empty
strings. Even in the latter case, the same instance is returned
on every call.
Locale
instance that matches this CountryCode
.public Currency getCurrency()
This method is an alias of Currency
.
getInstance
(
toLocale()
)
. The only difference is that this method
returns null
when Currency.getInstance(Locale)
throws IllegalArgumentException
.
This method returns null
when the territory represented by
this CountryCode
instance does not have a currency.
AQ
(Antarctica) is one example.
In addition, this method returns null
also when the ISO 3166
code represented by this CountryCode
instance is not
supported by the implementation of Currency.getInstance(Locale)
. At the time of this writing,
SS
(South Sudan) is one example.
Currency
instance. In some cases, null
is returned.Currency.getInstance(Locale)
public static CountryCode getByCode(String code)
CountryCode
that corresponds to the given ISO 3166-1
alpha-2 or
alpha-3 code.
This method calls getByCode
(code, true)
.
Note that the behavior has changed since the version 1.13. In the older versions,
this method was an alias of getByCode(code, false)
.
code
- An ISO 3166-1 alpha-2 or alpha-3 code.
When "UNDEFINED"
is given, CountryCode.UNDEFINED
is returned.
In addition, for backward compatibility, some 4-letter ISO 3166-3 codes such
as "ANHH"
are accepted.CountryCode
instance, or null
if not found.getByCode(String, boolean)
public static CountryCode getByCodeIgnoreCase(String code)
CountryCode
that corresponds to the given ISO 3166-1
alpha-2 or
alpha-3 code.
This method calls getByCode
(code, false)
.
code
- An ISO 3166-1 alpha-2 or alpha-3 code. Or "UNDEFINED"
(case insensitive).
In addition, for backward compatibility, some 4-letter ISO 3166-3 codes such
as "ANHH"
are accepted.CountryCode
instance, or null
if not found.getByCode(String, boolean)
public static CountryCode getByCode(String code, boolean caseSensitive)
code
- An ISO 3166-1 alpha-2 or alpha-3 code.
Or "UNDEFINED"
(its case sensitivity depends on the value of
caseSensitive
).
In addition, for backward compatibility, some 4-letter ISO 3166-3 codes such
as "ANHH"
are accepted.caseSensitive
- If true
, the given code should consist of upper-case letters only.
If false
, this method internally canonicalizes the given code by
String.toUpperCase()
and then performs search. For example,
getByCode("jp", true)
returns null
, but on the other hand,
getByCode("jp", false)
returns CountryCode.JP
.CountryCode
instance, or null
if not found.public static CountryCode getByLocale(Locale locale)
CountryCode
that corresponds to the country code of
the given Locale
instance.locale
- A Locale
instance.CountryCode
instance, or null
if not found.
When getCountry()
method of the
given Locale
instance returns null
or an
empty string, CountryCode.UNDEFINED
is
returned.Locale.getCountry()
public static CountryCode getByAlpha2Code(String code)
CountryCode
that corresponds to the given ISO 3166-1
alpha-2 code.code
- An ISO 3166-1 alpha-2 code.CountryCode
instance, or null
if not found.public static CountryCode getByAlpha3Code(String code)
CountryCode
that corresponds to the given ISO 3166-1
alpha-3 code.code
- An ISO 3166-1 alpha-3 code.CountryCode
instance, or null
if not found.public static CountryCode getByAlpha4Code(String code)
CountryCode
that corresponds to the given alpha-4 code.
Recognized alpha-4 codes are listed in the table below.
Alpha-4 Code CountryCode
ANHH
AN
BUMM
BU
CSXX
CS
NTHH
NT
TPTL
TP
YUCS
YU
ZRCD
ZR
code
- Alpha-4 code.CountryCode
instance, or null
if not found.public static CountryCode getByCode(int code)
CountryCode
that corresponds to the given
ISO 3166-1
numeric code.
Note that there are some pairs each of which shares the same numeric code.
The following table shows such pairs and which CountryCode
instance
is returned from this method.
Shared Numeric Code Alpha-3 Codes Returned Alpha-3 Code 104 BU
MM
MM
180 CD
ZR
CD
246 FI
SF
FI
826 GB
UK
GB
626 TL
TP
TL
code
- An ISO 3166-1 numeric code.CountryCode
instance, or null
if not found.
If 0 or a negative value is given, null
is returned.public static List<CountryCode> findByName(String regex)
CountryCode
by a name regular expression.
This method is almost equivalent to findByName
(Pattern.compile(regex))
.
regex
- Regular expression for names.CountryCode
. If nothing has matched,
an empty list is returned.IllegalArgumentException
- regex
is null
.PatternSyntaxException
- regex
failed to be compiled.public static List<CountryCode> findByName(Pattern pattern)
CountryCode
by a name pattern.
For example, the list obtained by the code snippet below:
Pattern pattern = Pattern.compile(".*United.*");
List<CountryCode> list = CountryCode.findByName(pattern);
contains 6 CountryCode
s as listed below.
pattern
- Pattern to match names.CountryCode
. If nothing has matched,
an empty list is returned.IllegalArgumentException
- pattern
is null
.Copyright © 2021. All rights reserved.