Pin It

How to display or get list of country names in Java ?.

Program to implement how to display or get list of country names in Java

package com.hubberspot.lists;

import java.util.Locale;

public class CountrysListDemo {

	public static void main(String[] args) {

		// Using Locale class static method getISOCountries()
		// we extract a list of all 2-letter country codes 
		// defined in ISO 3166. Can be used to create Locales.
		
		String[] countries = Locale.getISOCountries();
		
		// Loop each country 
		for(int i = 0; i < countries.length; i++) { 
			
			String country = countries[i];
			Locale locale = new Locale("en", country);
         
			// Get the country name by calling getDisplayCountry()
			String countryName = locale.getDisplayCountry();
         
			// Printing the country name on the console
         System.out.println(i+1 + " : " + countryName);
			
		}		
				
	}

}


Output of the program : 





















.
.
.
.
.



 
Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Related Posts Plugin for WordPress, Blogger...

Post your related queries below ...

comments powered by Disqus
Powered by Blogger.
 
© 2012 Learn Java by Examples Template by Hubber Spot