This example shows how to get country list in Java. Best way to get the list of countries is using getISOCountries method of Locale class.
The Locale.getISOCountries() will return a list of all 2-letter country codes defined in ISO 3166
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import java.util.Locale; public class ListCountry { public static void main(String[] args) { ListCountry obj = new ListCountry(); obj.run(); } public void run() { String[] locales = Locale.getISOCountries(); for (String countryCode : locales) { Locale obj = new Locale("", countryCode); System.out.println("Country Code = " + obj.getCountry() + ", Country Name = " + obj.getDisplayCountry()); } System.out.println("Done"); } } |
Output:
Country Code = AD, Country Name = Andorra
Country Code = AE, Country Name = United Arab Emirates
Country Code = AF, Country Name = Afghanistan
Country Code = AG, Country Name = Antigua and Barbuda
Country Code = AI, Country Name = Anguilla
Country Code = AL, Country Name = Albania
//skip ……
Country Code = AE, Country Name = United Arab Emirates
Country Code = AF, Country Name = Afghanistan
Country Code = AG, Country Name = Antigua and Barbuda
Country Code = AI, Country Name = Anguilla
Country Code = AL, Country Name = Albania
//skip ……