我已经能够获得一个国家/地区列表,但该名称以我的语言显示(意大利语)。我需要用英语表示,这就是我现在所拥有的(这段代码不是我的,我是从网上复制的)
String[] locales = Locale.getISOCountries();
ArrayList<String> list = new ArrayList<String>(500);
for (String countryCode : locales) {
Locale obj = new Locale("en", countryCode);
list.add(obj.getDisplayCountry());
}
Collections.sort(list);
country = new String[list.size()];
country = list.toArray(country);
谢谢=)
答案 0 :(得分:4)
您应该使用Locale.getDisplayCountry(Locale)
指定输出区域设置,例如
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));