Java Locale to get Countries List
Some times we may required to list of country names from XML or through properties file. On alternate way we can get list of country names using Java API also which gives most effective and generic way of using country names along with their country codes. In this tutorial we will see about how to get list of Countries using Java util class Locale. They may be a simple code where lot of Java developers aware of it, but gives new learning for freshers to Java. |
import java.util.Locale;
public class CountriesList {
public static void main(String[] args) {
String[] countriesList = Locale.getISOCountries();
int id = 1;
System.out.println("ID \t COUNTRY CODE \t COUNTRY NAME");
for (String country : countriesList) {
Locale tmp = new Locale("", country);
System.out.println((id++) +" \t "+tmp.getCountry() + " \t\t " + tmp.getDisplayCountry());
}
}
}
OUTPUT:
ID COUNTRY CODE COUNTRY NAME
1 AD Andorra
2 AE United Arab Emirates
3 AF Afghanistan
4 AG Antigua and Barbuda
5 AI Anguilla
6 AL Albania
7 AM Armenia
8 AN Netherlands Antilles
9 AO Angola
10 AQ Antarctica
11 AR Argentina
12 AS American Samoa
13 AT Austria
14 AU Australia
15 AW Aruba
16 AX Ã…land Islands
17 AZ Azerbaijan
18 BA Bosnia and Herzegovina
19 BB Barbados
20 BD Bangladesh
21 BE Belgium
22 BF Burkina Faso
23 BG Bulgaria
24 BH Bahrain
25 BI Burundi
26 BJ Benin
27 BL Saint Barthélemy
28 BM Bermuda
29 BN Brunei
30 BO Bolivia
31 BQ Bonaire, Sint Eustatius and Saba
32 BR Brazil
33 BS Bahamas
34 BT Bhutan
35 BV Bouvet Island
36 BW Botswana
37 BY Belarus
38 BZ Belize
39 CA Canada
40 CC Cocos Islands
41 CD The Democratic Republic Of Congo
42 CF Central African Republic
43 CG Congo
44 CH Switzerland
45 CI Côte d'Ivoire
46 CK Cook Islands
47 CL Chile
48 CM Cameroon
49 CN China
50 CO Colombia
51 CR Costa Rica
52 CU Cuba
53 CV Cape Verde
54 CW Curaçao
55 CX Christmas Island
56 CY Cyprus
57 CZ Czech Republic
58 DE Germany
59 DJ Djibouti
60 DK Denmark
61 DM Dominica
62 DO Dominican Republic
63 DZ Algeria
64 EC Ecuador
65 EE Estonia
66 EG Egypt
67 EH Western Sahara
68 ER Eritrea
69 ES Spain
70 ET Ethiopia
71 FI Finland
72 FJ Fiji
73 FK Falkland Islands
74 FM Micronesia
75 FO Faroe Islands
76 FR France
77 GA Gabon
78 GB United Kingdom
79 GD Grenada
80 GE Georgia
81 GF French Guiana
82 GG Guernsey
83 GH Ghana
84 GI Gibraltar
85 GL Greenland
86 GM Gambia
87 GN Guinea
88 GP Guadeloupe
89 GQ Equatorial Guinea
90 GR Greece
91 GS South Georgia And The South Sandwich Islands
92 GT Guatemala
93 GU Guam
94 GW Guinea-Bissau
95 GY Guyana
96 HK Hong Kong
97 HM Heard Island And McDonald Islands
98 HN Honduras
99 HR Croatia
100 HT Haiti
101 HU Hungary
102 ID Indonesia
103 IE Ireland
104 IL Israel
105 IM Isle Of Man
106 IN India
107 IO British Indian Ocean Territory
108 IQ Iraq
109 IR Iran
110 IS Iceland
111 IT Italy
112 JE Jersey
113 JM Jamaica
114 JO Jordan
115 JP Japan
116 KE Kenya
117 KG Kyrgyzstan
118 KH Cambodia
119 KI Kiribati
120 KM Comoros
121 KN Saint Kitts And Nevis
122 KP North Korea
123 KR South Korea
124 KW Kuwait
125 KY Cayman Islands
126 KZ Kazakhstan
127 LA Laos
128 LB Lebanon
129 LC Saint Lucia
130 LI Liechtenstein
131 LK Sri Lanka
132 LR Liberia
133 LS Lesotho
134 LT Lithuania
135 LU Luxembourg
136 LV Latvia
137 LY Libya
138 MA Morocco
139 MC Monaco
140 MD Moldova
141 ME Montenegro
142 MF Saint Martin
143 MG Madagascar
144 MH Marshall Islands
145 MK Macedonia
146 ML Mali
147 MM Myanmar
148 MN Mongolia
149 MO Macao
150 MP Northern Mariana Islands
151 MQ Martinique
152 MR Mauritania
153 MS Montserrat
154 MT Malta
155 MU Mauritius
156 MV Maldives
157 MW Malawi
158 MX Mexico
159 MY Malaysia
160 MZ Mozambique
161 NA Namibia
162 NC New Caledonia
163 NE Niger
164 NF Norfolk Island
165 NG Nigeria
166 NI Nicaragua
167 NL Netherlands
168 NO Norway
169 NP Nepal
170 NR Nauru
171 NU Niue
172 NZ New Zealand
173 OM Oman
174 PA Panama
175 PE Peru
176 PF French Polynesia
177 PG Papua New Guinea
178 PH Philippines
179 PK Pakistan
180 PL Poland
181 PM Saint Pierre And Miquelon
182 PN Pitcairn
183 PR Puerto Rico
184 PS Palestine
185 PT Portugal
186 PW Palau
187 PY Paraguay
188 QA Qatar
189 RE Reunion
190 RO Romania
191 RS Serbia
192 RU Russia
193 RW Rwanda
194 SA Saudi Arabia
195 SB Solomon Islands
196 SC Seychelles
197 SD Sudan
198 SE Sweden
199 SG Singapore
200 SH Saint Helena
201 SI Slovenia
202 SJ Svalbard And Jan Mayen
203 SK Slovakia
204 SL Sierra Leone
205 SM San Marino
206 SN Senegal
207 SO Somalia
208 SR Suriname
209 ST Sao Tome And Principe
210 SV El Salvador
211 SX Sint Maarten (Dutch part)
212 SY Syria
213 SZ Swaziland
214 TC Turks And Caicos Islands
215 TD Chad
216 TF French Southern Territories
217 TG Togo
218 TH Thailand
219 TJ Tajikistan
220 TK Tokelau
221 TL Timor-Leste
222 TM Turkmenistan
223 TN Tunisia
224 TO Tonga
225 TR Turkey
226 TT Trinidad and Tobago
227 TV Tuvalu
228 TW Taiwan
229 TZ Tanzania
230 UA Ukraine
231 UG Uganda
232 UM United States Minor Outlying Islands
233 US United States
234 UY Uruguay
235 UZ Uzbekistan
236 VA Vatican
237 VC Saint Vincent And The Grenadines
238 VE Venezuela
239 VG British Virgin Islands
240 VI U.S. Virgin Islands
241 VN Vietnam
242 VU Vanuatu
243 WF Wallis And Futuna
244 WS Samoa
245 YE Yemen
246 YT Mayotte
247 ZA South Africa
248 ZM Zambia
249 ZW Zimbabwe