Enum Class CountryCode
- All Implemented Interfaces:
Serializable
,Comparable<CountryCode>
,java.lang.constant.Constable
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
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum ConstantDescriptionAscension Island [AC, ASC, -1, Exceptionally reserved]United Arab Emirates [AE, AE, 784, Officially assigned]Afghanistan [AF, AFG, 4, Officially assigned]Antigua and Barbuda [AG, ATG, 28, Officially assigned]Netherlands Antilles [AN, ANT, 530, Traditionally reserved]Antarctica [AQ, ATA, 10, Officially assigned]American Samoa [AS, ASM, 16, Officially assigned]Åland Islands [AX, ALA, 248, Officially assigned]Azerbaijan [AZ, AZE, 31, Officially assigned]Bosnia and Herzegovina [BA, BIH, 70, Officially assigned]Bangladesh [BD, BGD, 50, Officially assigned]Burkina Faso [BF, BFA, 854, Officially assigned]Saint Barthélemy [BL, BLM, 652, Officially assigned]Brunei Darussalam [BN, BRN, 96, Officially assigned]Bolivia, Plurinational State of [BO, BOL, 68, Officially assigned]Bonaire, Sint Eustatius and Saba [BQ, BES, 535, Officially assigned]Bouvet Island [BV, BVT, 74, Officially assigned]Cocos (Keeling) Islands [CC, CCK, 166, Officially assigned]Congo, the Democratic Republic of the [CD, COD, 180, Officially assigned]Central African Republic [CF, CAF, 140, Officially assigned]Switzerland [CH, CHE, 756, Officially assigned]Côte d'Ivoire [CI, CIV, 384, Officially assigned]Cook Islands [CK, COK, 184, Officially assigned]Clipperton Island [CP, CPT, -1, Exceptionally reserved]Costa Rica [CR, CRI, 188, Officially assigned]Serbia and Montenegro [CS, SCG, 891, Traditionally reserved]Cape Verde [CV, CPV, 132, Officially assigned]Christmas Island [CX, CXR, 162, Officially assigned]Czech Republic [CZ, CZE, 203, Officially assigned]Diego Garcia [DG, DGA, -1, Exceptionally reserved]Dominican Republic [DO, DOM, 214, Officially assigned]Western Sahara [EH, ESH, 732, Officially assigned]European Union [EU, null, -1, Exceptionally reserved]Falkland Islands (Malvinas) [FK, FLK, 238, Officially assigned]Micronesia, Federated States of [FM, FSM, 583, Officially assigned]Faroe Islands [FO, FRO, 234, Officially assigned]France, Metropolitan [FX, FXX, 249, Exceptionally reserved]United Kingdom [GB, GBR, 826, Officially assigned]French Guiana [GF, GUF, 254, Officially assigned]Guadeloupe [GP, GLP, 312, Officially assigned]Equatorial Guinea [GQ, GNQ, 226, Officially assigned]South Georgia and the South Sandwich Islands [GS, SGS, 239, Officially assigned]Guinea-Bissau [GW, GNB, 624, Officially assigned]Heard Island and McDonald Islands [HM, HMD, 334, Officially assigned]Canary Islands [IC, null, -1, Exceptionally reserved]Isle of Man [IM, IMN, 833, Officially assigned]British Indian Ocean Territory [IO, IOT, 86, Officially assigned]Iran, Islamic Republic of [IR, IRN, 364, Officially assigned]Kyrgyzstan [KG, KGZ, 417, Officially assigned]Saint Kitts and Nevis [KN, KNA, 659, Officially assigned]Korea, Democratic People's Republic of [KP, PRK, 408, Officially assigned]Korea, Republic of [KR, KOR, 410, Officially assigned]Cayman Islands [KY, CYM, 136, Officially assigned]Kazakhstan [KZ, KAZ, 398, Officially assigned]Lao People's Democratic Republic [LA, LAO, 418, Officially assigned]Saint Lucia [LC, LCA, 662, Officially assigned]Liechtenstein [LI, LIE, 438, Officially assigned]Luxembourg [LU, LUX, 442, Officially assigned]Moldova, Republic of [MD, MDA, 498, Officially assigned]Montenegro [ME, MNE, 499, Officially assigned]Saint Martin (French part) [MF, MAF, 663, Officially assigned]Madagascar [MG, MDG, 450, Officially assigned]Marshall Islands [MH, MHL, 584, Officially assigned]North Macedonia, Republic of [MK, MKD, 807, Officially assigned]Northern Mariana Islands [MP, MNP, 580, Officially assigned]Martinique [MQ, MTQ, 474, Officially assigned]Mauritania [MR, MRT, 478, Officially assigned]Montserrat [MS, MSR, 500, Officially assigned]Mozambique [MZ, MOZ, 508, Officially assigned]New Caledonia [NC, NCL, 540, Officially assigned]Norfolk Island [NF, NFK, 574, Officially assigned]Netherlands [NL, NLD, 528, Officially assigned]Neutral Zone [NT, NTZ, 536, Traditionally reserved]New Zealand [NZ, NZL, 554, Officially assigned]<a href=http://en.wikipedia.org/wiki/Oman"">Oman [OM, OMN, 512, Officially assigned]French Polynesia [PF, PYF, 258, Officially assigned]Papua New Guinea [PG, PNG, 598, Officially assigned]Philippines [PH, PHL, 608, Officially assigned]Saint Pierre and Miquelon [PM, SPM, 666, Officially assigned]Puerto Rico [PR, PRI, 630, Officially assigned]Palestine, State of [PS, PSE, 275, Officially assigned]Russian Federation [RU, RUS, 643, Officially assigned]Saudi Arabia [SA, SAU, 682, Officially assigned]Solomon Islands [SB, SLB, 90, Officially assigned]Seychelles [SC, SYC, 690, Officially assigned]Saint Helena, Ascension and Tristan da Cunha [SH, SHN, 654, Officially assigned]Svalbard and Jan Mayen [SJ, SJM, 744, Officially assigned]Sierra Leone [SL, SLE, 694, Officially assigned]San Marino [SM, SMR, 674, Officially assigned]South Sudan [SS, SSD, 728, Officially assigned]Sao Tome and Principe [ST, STP, 678, Officially assigned]El Salvador [SV, SLV, 222, Officially assigned]Sint Maarten (Dutch part) [SX, SXM, 534, Officially assigned]Syrian Arab Republic [SY, SYR, 760, Officially assigned]Tristan da Cunha [TA, TAA, -1, Exceptionally reserved.Turks and Caicos Islands [TC, TCA, 796, Officially assigned]French Southern Territories [TF, ATF, 260, Officially assigned]Tajikistan [TJ, TJK, 762, Officially assigned]Timor-Leste [TL, TLS, 626, Officially assigned]Turkmenistan [TM, TKM, 795, Officially assigned]East Timor [TP, TMP, 626, Traditionally reserved]Trinidad and Tobago [TT, TTO, 780, Officially assigned]Taiwan, Province of China [TW, TWN, 158, Officially assigned]Tanzania, United Republic of [TZ, TZA, 834, Officially assigned]United Kingdom [UK, null, 826, Exceptionally reserved]United States Minor Outlying Islands [UM, UMI, 581, Officially assigned]Undefined [UNDEFINED, null, -1, User assigned]United States [US, USA, 840, Officially assigned]Uzbekistan [UZ, UZB, 860, Officially assigned]Holy See (Vatican City State) [VA, VAT, 336, Officially assigned]Saint Vincent and the Grenadines [VC, VCT, 670, Officially assigned]Venezuela, Bolivarian Republic of [VE, VEN, 862, Officially assigned]Virgin Islands, British [VG, VGB, 92, Officially assigned]Virgin Islands, U.S. [VI, VIR, 850, Officially assigned]Wallis and Futuna [WF, WLF, 876, Officially assigned]Northern Ireland [XI, XXI, -1, User assigned]Kosovo, Republic of [XK, XXK, -1, User assigned]Yugoslavia [YU, YUG, 890, Traditionally reserved]South Africa [ZA, ZAF, 710, Officially assigned] -
Method Summary
Modifier and TypeMethodDescriptionstatic List<CountryCode>
findByName
(String regex) Get a list ofCountryCode
by a name regular expression.static List<CountryCode>
findByName
(Pattern pattern) Get a list ofCountryCode
by a name pattern.Get the ISO 3166-1 alpha-2 code.Get the ISO 3166-1 alpha-3 code.Get the assignment state of this country code in ISO 3166-1.static CountryCode
getByAlpha2Code
(String code) Get aCountryCode
that corresponds to the given ISO 3166-1 alpha-2 code.static CountryCode
getByAlpha3Code
(String code) Get aCountryCode
that corresponds to the given ISO 3166-1 alpha-3 code.static CountryCode
getByAlpha4Code
(String code) Get aCountryCode
that corresponds to the given alpha-4 code.static CountryCode
getByCode
(int code) Get aCountryCode
that corresponds to the given ISO 3166-1 numeric code.static CountryCode
static CountryCode
static CountryCode
getByCodeIgnoreCase
(String code) static CountryCode
getByLocale
(Locale locale) Get aCountryCode
that corresponds to the country code of the givenLocale
instance.Get the currency.getName()
Get the country name.int
Get the ISO 3166-1 numeric code.toLocale()
Convert thisCountryCode
instance to aLocale
instance.static CountryCode
Returns the enum constant of this class with the specified name.static CountryCode[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
UNDEFINED
Undefined [UNDEFINED, null, -1, User assigned]This is not an official ISO 3166-1 code.
- Since:
- 1.14
-
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]Since version 1.16, the value of alpha-3 code of this entry is
ANT
(notANHH
). -
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]The country name was changed from "â„«land Islands" (up to 1.14) to "Ã…land Islands" (since 1.15).
-
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
Burma [BU, BUMM, 104, Officially assigned]Since version 1.16, the value of alpha-3 code of this entry is
BUR
(notBUMM
).- See Also:
-
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]- See Also:
-
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]Since version 1.16, the value of alpha-3 code of this entry is
SCG
(notCSXX
). -
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
- Since:
- 1.23
-
FI
- See Also:
-
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]Since version 1.17, the numeric code of this entry is 249.
-
GA
-
GB
United Kingdom [GB, GBR, 826, Officially assigned]- See Also:
-
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
- See Also:
-
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]Since version 1.16, the value of alpha-3 code of this entry is
NTZ
(notNTHH
). -
NU
-
NZ
New Zealand [NZ, NZL, 554, Officially assigned] -
OM
<a href=http://en.wikipedia.org/wiki/Oman"">Oman [OM, OMN, 512, Officially assigned] -
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
- See Also:
-
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]- See Also:
-
TM
Turkmenistan [TM, TKM, 795, Officially assigned] -
TN
-
TO
-
TP
East Timor [TP, TMP, 626, Traditionally reserved]Since version 1.16, the value of alpha-3 code of this entry is
TMP
(notTPTL
).Since version 1.17, the numeric code of this entry is 626.
- See Also:
-
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]Since version 1.17, the numeric code of this entry is 826.
- See Also:
-
UM
United States Minor Outlying Islands [UM, UMI, 581, Officially 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]- Since:
- 1.28
-
XK
Kosovo, Republic of [XK, XXK, -1, User assigned] -
YE
-
YT
-
YU
Yugoslavia [YU, YUG, 890, Traditionally reserved]Since version 1.16, the value of alpha-3 code of this entry is
YUG
(notYUCS
). -
ZA
South Africa [ZA, ZAF, 710, Officially assigned] -
ZM
-
ZR
Zaire [ZR, ZAR, 180, Traditionally reserved]Since version 1.16, the value of alpha-3 code of this entry is
ZAR
(notZRCD
).Since version 1.17, the numeric code of this entry is 180.
- See Also:
-
ZW
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum class has no constant with the specified nameNullPointerException
- if the argument is null
-
getByCode
Get aCountryCode
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 ofgetByCode(code, false)
.- Parameters:
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.- Returns:
- A
CountryCode
instance, ornull
if not found. - See Also:
-
getByCodeIgnoreCase
Get aCountryCode
that corresponds to the given ISO 3166-1 alpha-2 or alpha-3 code.This method calls
getByCode
(code, false)
.- Parameters:
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.- Returns:
- A
CountryCode
instance, ornull
if not found. - Since:
- 1.13
- See Also:
-
getByCode
- Parameters:
code
- An ISO 3166-1 alpha-2 or alpha-3 code. Or"UNDEFINED"
(its case sensitivity depends on the value ofcaseSensitive
). In addition, for backward compatibility, some 4-letter ISO 3166-3 codes such as"ANHH"
are accepted.caseSensitive
- Iftrue
, the given code should consist of upper-case letters only. Iffalse
, this method internally canonicalizes the given code byString.toUpperCase()
and then performs search. For example,getByCode("jp", true)
returnsnull
, but on the other hand,getByCode("jp", false)
returnsCountryCode.JP
.- Returns:
- A
CountryCode
instance, ornull
if not found.
-
getByLocale
Get aCountryCode
that corresponds to the country code of the givenLocale
instance.- Parameters:
locale
- ALocale
instance.- Returns:
- A
CountryCode
instance, ornull
if not found. WhengetCountry()
method of the givenLocale
instance returnsnull
or an empty string,CountryCode.UNDEFINED
is returned. - See Also:
-
getByAlpha2Code
Get aCountryCode
that corresponds to the given ISO 3166-1 alpha-2 code.- Parameters:
code
- An ISO 3166-1 alpha-2 code.- Returns:
- A
CountryCode
instance, ornull
if not found. - Since:
- 1.23
-
getByAlpha3Code
Get aCountryCode
that corresponds to the given ISO 3166-1 alpha-3 code.- Parameters:
code
- An ISO 3166-1 alpha-3 code.- Returns:
- A
CountryCode
instance, ornull
if not found. - Since:
- 1.23
-
getByAlpha4Code
Get aCountryCode
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
- Parameters:
code
- Alpha-4 code.- Returns:
- A
CountryCode
instance, ornull
if not found. - Since:
- 1.23
-
getByCode
Get aCountryCode
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
- Parameters:
code
- An ISO 3166-1 numeric code.- Returns:
- A
CountryCode
instance, ornull
if not found. If 0 or a negative value is given,null
is returned.
-
findByName
Get a list ofCountryCode
by a name regular expression.This method is almost equivalent to
findByName
(Pattern.compile(regex))
.- Parameters:
regex
- Regular expression for names.- Returns:
- List of
CountryCode
. If nothing has matched, an empty list is returned. - Throws:
IllegalArgumentException
-regex
isnull
.PatternSyntaxException
-regex
failed to be compiled.- Since:
- 1.11
-
findByName
Get a list ofCountryCode
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.- Parameters:
pattern
- Pattern to match names.- Returns:
- List of
CountryCode
. If nothing has matched, an empty list is returned. - Throws:
IllegalArgumentException
-pattern
isnull
.- Since:
- 1.11
-
getName
Get the country name.- Returns:
- The country name.
-
getAlpha2
Get the ISO 3166-1 alpha-2 code.- Returns:
- The ISO 3166-1 alpha-2 code.
UNDEFINED
returns"UNDEFINED"
which is not an official ISO 3166-1 alpha-2 code.
-
getAlpha3
Get the ISO 3166-1 alpha-3 code.- Returns:
- The ISO 3166-1 alpha-3 code.
Some country codes reserved exceptionally (such as
EU
) returnsnull
.UNDEFINED
returnsnull
, too.
-
getNumeric
public int getNumeric()Get the ISO 3166-1 numeric code.- Returns:
- The ISO 3166-1 numeric code.
Country codes reserved exceptionally (such as
EU
) returns-1
.UNDEFINED
returns-1
, too.
-
getAssignment
Get the assignment state of this country code in ISO 3166-1.- Returns:
- The assignment state.
- See Also:
-
toLocale
Convert thisCountryCode
instance to aLocale
instance.In most cases, this method creates a new
Locale
instance every time it is called, but someCountryCode
instances return their corresponding entries inLocale
class. For example,CountryCode.CA
always returnsLocale.CANADA
.The table below lists
CountryCode
entries whosetoLocale()
do not create new Locale instances but return entries inLocale
class.In addition,
toLocale()
ofCountryCode.UNDEFINED
behaves a bit differently. It returnsLocale.ROOT
when it is available (i.e. when the version of Java SE is 1.6 or higher). Otherwise, it returns aLocale
instance whose language and country are empty strings. Even in the latter case, the same instance is returned on every call.- Returns:
- A
Locale
instance that matches thisCountryCode
.
-
getCurrency
Get the currency.This method is an alias of
Currency
.
getInstance
(
toLocale()
)
. The only difference is that this method returnsnull
whenCurrency.getInstance(Locale)
throwsIllegalArgumentException
.This method returns
null
when the territory represented by thisCountryCode
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 thisCountryCode
instance is not supported by the implementation ofCurrency.getInstance(Locale)
. At the time of this writing,SS
(South Sudan) is one example.- Returns:
- A
Currency
instance. In some cases, null is returned. - Since:
- 1.4
- See Also:
-