This content has been marked as final. Show 3 replies
babus_18 wrote:No, it isn't the right approach. You created a new Locale. How should it know what's the correct country name if you don't tell it? If you try Locale.US.getDisplayCountry() you may get better results.
But I was expecting to see "United States". Is this the right approach to resolving country codes to country names?
However if you're looking for something which maps "gt" to Guatemala it's probably easier for you to just hard-code a Map which contains that information. Or see if somebody has done it already and posted it on the web.
There was a issue with the code above and hence it wasn't returning the correct country name.
The signature for the single argument Locale constructor is Locale(String language). So I was passing "us" as the language. Hence the issue.
The following code snippet generates "United States"
Locale locale = new Locale("", "us"); System.out.println(locale.getDisplayCountry());