How do I get a list of country names?

Bookmark this example!  
Category: java.util, viewed: 1653 time(s).

Using the code below you can get a list of country names and its ISO code by using the locale class implementation in Java.

 
package org.kodejava.example.util;
 
import java.util.Locale;
 
public class CountryNames {
	public static void main(String[] args) {
		Locale[] locales = Locale.getAvailableLocales();
		
		for (int i = 0; i < locales.length; i++) {
			String iso = locales[i].getCountry();
			String name = locales[i].getDisplayCountry();
			
			if (!"".equals(iso) && !"".equals(name)) {
				System.out.println(iso + " - " + name);
			}
		}
	}
}
 
 
Can't find what you are looking for? Join our FORUMS and ask some questions!

Most Viewed Examples

Latest Code Examples

100 Top & Latest


Locations of visitors to this page
eXTReMe Tracker
visitor stats
Get Chitika Premium