You could use the built-in Locale
class:
Locale l = new Locale("", "CH");
System.out.println(l.getDisplayCountry());
prints "Switzerland" for example. Note that I have not provided a language.
So what you can do for the reverse lookup is build a map from the available countries:
public static void main(String[] args) throws InterruptedException {
Map<String, String> countries = new HashMap<>();
for (String iso : Locale.getISOCountries()) {
Locale l = new Locale("", iso);
countries.put(l.getDisplayCountry(), iso);
}
System.out.println(countries.get("Switzerland"));
System.out.println(countries.get("Andorra"));
System.out.println(countries.get("Japan"));
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…