Get country name from country code

This should work:

Locale l = new Locale("", "NL");
String country = l.getDisplayCountry();

The first parameter of Locale is the language, which is not useful in your case.


I would like to add more information to the answers above.

If you want to specify language for results, you can use Locale("your language") as the parameter of getDisplayCountry().

For example:

(new Locale("","NL")).getDisplayCountry(new Locale("ZH"));

"ZH" is the language code of Chinese. You will get "荷兰", which is the Chinese name of Netherlands.

And you can use Locale("languages", "ISO-3166 code") to specify your language variant.

for example:

(new Locale("","NL")).getDisplayCountry(new Locale("ZH", "TW"));

Locale("ZH", "TW") means the variant of Chinese in Taiwan (traditional Chinese). It has many differences from the Chinese Mainland variant.

You will get "荷蘭", which is the traditional Chinese name of Netherlands.

(Even if you don’t understand Chinese, I think it's obvious that the second Chinese character in the two names is different.)

If you do not specify a language, you will get the name of Netherlands in the device display language, which can be changed in the phone settings. The code is:

(new Locale("","NL")).getDisplayCountry();

You can get a list of all languages and variants supported by Android in this question :

If you're using kotlin:

Locale("", "NL").getDisplayCountry(Locale("ZH"))
Locale("", "NL").getDisplayCountry(Locale("ZH", "TW"))
Locale("", "NL").displayCountry

try like this

Locale loc = new Locale("","NL");
loc.getDisplayCountry();

Hope this will help out.

Tags:

Android

Locale