Java 以确定的语言获取国家/地区列表

Java 以确定的语言获取国家/地区列表,java,country-codes,Java,Country Codes,我已经能够得到一个国家的名单,但是名字用我的语言(意大利语)显示出来了。我需要他们以英语显示,这是我现在拥有的(这个代码不是我的,我从网上复制的) String[]locales=Locale.getISOCountries(); ArrayList=新的ArrayList(500); for(字符串countryCode:locales){ 语言环境obj=新语言环境(“en”,国家代码); 添加(obj.getDisplayCountry()); } 集合。排序(列表); country=新

我已经能够得到一个国家的名单,但是名字用我的语言(意大利语)显示出来了。我需要他们以英语显示,这是我现在拥有的(这个代码不是我的,我从网上复制的)

String[]locales=Locale.getISOCountries();
ArrayList=新的ArrayList(500);
for(字符串countryCode:locales){
语言环境obj=新语言环境(“en”,国家代码);
添加(obj.getDisplayCountry());
}
集合。排序(列表);
country=新字符串[list.size()];
国家=列表。toArray(国家);

Thank you=)

您应该使用和类似的方式指定输出区域设置

String[] locales = Locale.getISOCountries();
List<String> list = new ArrayList<>(500); // <-- List interface, and diamond
                                          //     operator.
Locale outLocale = new Locale("EN", "us"); // <-- English US
for (String countryCode : locales) {
    Locale obj = new Locale("en-us", countryCode);
    list.add(obj.getDisplayCountry(outLocale));
}
Collections.sort(list);
String[] country = list.toArray(new String[list.size()]);
System.out.println(Arrays.toString(country));
String[]locales=Locale.getISOCountries();

列表列表=新阵列列表(500);// 您应该使用和类似的方式指定输出区域设置

String[] locales = Locale.getISOCountries();
List<String> list = new ArrayList<>(500); // <-- List interface, and diamond
                                          //     operator.
Locale outLocale = new Locale("EN", "us"); // <-- English US
for (String countryCode : locales) {
    Locale obj = new Locale("en-us", countryCode);
    list.add(obj.getDisplayCountry(outLocale));
}
Collections.sort(list);
String[] country = list.toArray(new String[list.size()]);
System.out.println(Arrays.toString(country));
String[]locales=Locale.getISOCountries();
列表=新的ArrayList(500)//