Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to get a list of countries in Java

Tags:

Other than Locale.getISOCountries() that is, because I'm already getting some strange errors with that. What else is the best way to get the 2-letter country codes as well as the full country name?

like image 783
Ali Avatar asked Apr 03 '09 01:04

Ali


People also ask

What countries are on Java?

Java, also spelled Djawa or Jawa, island of Indonesia lying southeast of Malaysia and Sumatra, south of Borneo (Kalimantan), and west of Bali. Java is home to roughly half of Indonesia's population and dominates the country politically and economically.

Is there a country name Java?

Java (Indonesian: Jawa, Indonesian pronunciation: [ˈdʒawa]; Javanese: ꦗꦮ; Sundanese: ᮏᮝ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north.

How can I get country code in android programmatically?

Show activity on this post. TelephonyManager tm = (TelephonyManager)getSystemService(getApplicationContext(). TELEPHONY_SERVICE); String countryCode = tm. getNetworkCountryIso();

What is Java locale?

The Java Locale class object represents a specific geographic, cultural, or political region. It is a mechanism to for identifying objects, not a container for the objects themselves. A Locale object logically consists of the fields like languages, script, country, variant, extensions.


1 Answers

See code snippets :

String[] countryCodes = Locale.getISOCountries();  for (String countryCode : countryCodes) {      Locale obj = new Locale("", countryCode);      System.out.println("Country Code = " + obj.getCountry()          + ", Country Name = " + obj.getDisplayCountry());  } 

Refer to this country list in Java for more examples.

like image 96
mkyong Avatar answered Sep 18 '22 17:09

mkyong