The getISOCountries () method displays only two letters of contry name. Is it possible to get the full name of the country using this method?

I used the following code, but it only displays 2 digits of the ISO country name. For example, for "INDIA" it displays only "IN". Can I show the full name as "INDIA"?

String[] loc= Locale.getISOCountries(); for(int a=0;a<loc.length;a++) { System.out.println("ISO Contry "+a+":"+loc[a]); } 

I need the full name of the ISO country. Can this method be used?

+4
source share
3 answers

Try using the getDisplayCountry () method .

Example:

 import java.util.Locale; public class Main { public static void main(String [] argv) { Locale defaultLocale = Locale.getDefault(); System.out.println(defaultLocale.getDisplayCountry()); // displays United States } } 

EDIT: To get a complete list of full country names, I don't know any methods. Instead, you can download this ISO 3166 code , which contains a mapping of the full country name with a 2-letter letter to the two-letter name of ISO 3166, use your previous getISOCountries method to get the 2-letter name and use the mapping.

+4
source

Here we can only get the full name of Locale, which are available in the getAvailableLocale() method.

 import java.util.*; public class Locales { public static void main(String[] args) { Locale[] locales = Locale.getAvailableLocales(); for(int i = 0; i < locales.length; i++) { String locale_name = locales[i].getDisplayName(); System.out.println((i+1)+":"+locale_name); } } } 
+1
source

No need to download files. You can again create a Locale object with the specified two letters of the country so that you do this:

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

Source: https://habr.com/ru/post/1302838/


All Articles