How to Get List of All Country Codes in Java Using Locale Class


Make use of the below code if you want to work with the list of Countries in the World and their 2-character ISO country codes.

   /**
     * Method to get a sorted map of country names and their
     * ISO 3166 Country Codes
     * 
     * @return Treemap of <Country,Country Code>
     */
    public Map<String,String> getCountryCodeDetails() {

        Map<String, String> mapOfCountryAndCodes = new TreeMap();
        String[] countriesLocaleArr = Locale.getISOCountries();

        for (String countryCode : countriesLocaleArr) {

            Locale locale = new Locale("en", countryCode);
            mapOfCountryAndCodes.put(locale.getCountry(), locale.getDisplayCountry());

        }
       return mapOfCountryAndCodes;

    }
Example:
Map<String,String> countryCodeMap = countryCodes.getCountryCodeDetails();
countryCodeMap.forEach((code, country) -> System.out.println((code + ": " + country)));
Output List:

A

Country CodeCountry Name
ADAndorra
AEUnited Arab Emirates
AFAfghanistan
AGAntigua & Barbuda
AIAnguilla
ALAlbania
AMArmenia
ANNetherlands Antilles
AOAngola
AQAntarctica
ARArgentina
ASAmerican Samoa

B

Country CodeCountry Name
ATAustria
AUAustralia
AWAruba
AXÅland Islands
AZAzerbaijan
BABosnia & Herzegovina
BBBarbados
BDBangladesh
BEBelgium
BFBurkina Faso
BGBulgaria
BHBahrain
BIBurundi
BJBenin
BLSt. Barthélemy
BMBermuda
BNBrunei
BOBolivia
BQCaribbean Netherlands
BRBrazil
BSBahamas
BTBhutan
BVBouvet Island
BWBotswana
BYBelarus
BZBelize

C

Country CodeCountry Name
CACanada
CCCocos (Keeling) Islands
CDCongo - Kinshasa
CFCentral African Republic
CGCongo - Brazzaville
CHSwitzerland
CICôte d’Ivoire
CKCook Islands
CLChile
CMCameroon
CNChina
COColombia
CRCosta Rica
CUCuba
CVCape Verde
CWCuraçao
CXChristmas Island
CYCyprus
CZCzechia

D

Country CodeCountry Name
DEGermany
DJDjibouti
DKDenmark
DMDominica
DODominican Republic
DZAlgeria

E

Country CodeCountry Name
ECEcuador
EEEstonia
EGEgypt
EHWestern Sahara
EREritrea
ESSpain
ETEthiopia

F

Country CodeCountry Name
FIFinland
FJFiji
FKFalkland Islands
FMMicronesia
FOFaroe Islands
FRFrance

G

Country CodeCountry Name
GAGabon
GBUnited Kingdom
GDGrenada
GEGeorgia
GFFrench Guiana
GGGuernsey
GHGhana
GIGibraltar
GLGreenland
GMGambia
GNGuinea
GPGuadeloupe
GQEquatorial Guinea
GRGreece
GSSouth Georgia & South Sandwich Islands
GTGuatemala
GUGuam
GWGuinea-Bissau
GYGuyana

H

Country CodeCountry Name
HKHong Kong SAR China
HMHeard & McDonald Islands
HNHonduras
HRCroatia
HTHaiti
HUHungary

I

Country CodeCountry Name
IDIndonesia
IEIreland
ILIsrael
IMIsle of Man
INIndia
IOBritish Indian Ocean Territory
IQIraq
IRIran
ISIceland
ITItaly

J

Country CodeCountry Name
JEJersey
JMJamaica
JOJordan
JPJapan

K

Country CodeCountry Name
KEKenya
KGKyrgyzstan
KHCambodia
KIKiribati
KMComoros
KNSt. Kitts & Nevis
KPNorth Korea
KRSouth Korea
KWKuwait
KYCayman Islands
KZKazakhstan

L

Country CodeCountry Name
LALaos
LBLebanon
LCSt. Lucia
LILiechtenstein
LKSri Lanka
LRLiberia
LSLesotho
LTLithuania
LULuxembourg
LVLatvia
LYLibya

M

Country CodeCountry Name
MAMorocco
MCMonaco
MDMoldova
MEMontenegro
MFSt. Martin
MGMadagascar
MHMarshall Islands
MKNorth Macedonia
MLMali
MMMyanmar (Burma)
MNMongolia
MOMacao SAR China
MPNorthern Mariana Islands
MQMartinique
MRMauritania
MSMontserrat
MTMalta
MUMauritius
MVMaldives
MWMalawi
MXMexico
MYMalaysia
MZMozambique

N

Country CodeCountry Name
NANamibia
NCNew Caledonia
NENiger
NFNorfolk Island
NGNigeria
NINicaragua
NLNetherlands
NONorway
NPNepal
NRNauru
NUNiue
NZNew Zealand

O

Country CodeCountry Name
OMOman

P

Country CodeCountry Name
PAPanama
PEPeru
PFFrench Polynesia
PGPapua New Guinea
PHPhilippines
PKPakistan
PLPoland
PMSt. Pierre & Miquelon
PNPitcairn Islands
PRPuerto Rico
PSPalestinian Territories
PTPortugal
PWPalau
PYParaguay

Q

Country CodeCountry Name
QAQatar

R

Country CodeCountry Name
RERéunion
RORomania
RSSerbia
RURussia
RWRwanda

S

Country CodeCountry Name
SASaudi Arabia
SBSolomon Islands
SCSeychelles
SDSudan
SESweden
SGSingapore
SHSt. Helena
SISlovenia
SJSvalbard & Jan Mayen
SKSlovakia
SLSierra Leone
SMSan Marino
SNSenegal
SOSomalia
SRSuriname
SSSouth Sudan
STSão Tomé & Príncipe
SVEl Salvador
SXSint Maarten
SYSyria
SZEswatini

T

Country CodeCountry Name
TCTurks & Caicos Islands
TDChad
TFFrench Southern Territories
TGTogo
THThailand
TJTajikistan
TKTokelau
TLTimor-Leste
TMTurkmenistan
TNTunisia
TOTonga
TRTurkey
TTTrinidad & Tobago
TVTuvalu
TWTaiwan
TZTanzania

U

Country CodeCountry Name
UAUkraine
UGUganda
UMU.S. Outlying Islands
USUnited States
UYUruguay
UZUzbekistan

V

Country CodeCountry Name
VAVatican City
VCSt. Vincent & Grenadines
VEVenezuela
VGBritish Virgin Islands
VIU.S. Virgin Islands
VNVietnam
VUVanuatu

W

Country CodeCountry Name
WFWallis & Futuna
WSSamoa
YEYemen
YTMayotte

Z

Country CodeCountry Name
ZASouth Africa
ZMZambia
ZWZimbabwe
Java-List-of-Country-Codes

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap