本文介绍了getISOCountries()方法仅显示两个连续名称.使用这种方法可以获取国家的全名吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了以下代码,但它仅显示2位ISO国家/地区名称.例如,对于"INDIA",它仅显示"IN".我可以将全名显示为"INDIA"吗?

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

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

我想要ISO国家的全名.可以使用这种方法吗?

I want full name of ISO country. Is it possible to get using this method?

推荐答案

尝试使用 getDisplayCountry() 方法.

Try using getDisplayCountry() method.

示例:

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
  }
}

要获取完整的国家名称的完整列表,我不知道任何方法.相反,您可以做的是,下载此 ISO 3166代码 (其中包含完整的国家名称到2个字母的映射到两个字母的ISO 3166名称),请使用之前的getISOCountries方法获取2个字母的名称并使用该映射.

To get the complete list of full country names, I'm not aware of any methods. Instead what you can do is, download this ISO 3166 Codes which contains the mapping of full country name to 2-letter to two letter ISO 3166 name, use your earlier getISOCountries method to get the 2 letter name and use the mapping.

这篇关于getISOCountries()方法仅显示两个连续名称.使用这种方法可以获取国家的全名吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 14:58