Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java code to convert country codes alpha-2 (IN) to alpha 3 (IND)

Using Java, Is there a quick way to convert an alpha-2 country code (IN or GB) to the alpha-3 equivalent (IND or GBR)?

I can get the alpha-2 codes with:

String[] codes = java.util.Locale.getISOLanguages();

That's not a problem, actually my application reads in the alpha-2 code, but I need to output the alpha-3 equivalent .

Is there a similar way like above to get the alpha-3 codes?

Any suggestions?

like image 699
Mbg Avatar asked Sep 01 '10 10:09

Mbg


2 Answers

This works -

    Locale locale = new Locale("en","IN");
    System.out.println("Country=" + locale.getISO3Country());

Output:

Country=IND
like image 119
Gopi Avatar answered Sep 24 '22 12:09

Gopi


Yes, simple create a Locale and get if from the locale:

String alpha3Country = new Locale("en", alpha2County).getISO3Country();

BTW: getISOLanguages() returns language codes (lowercase), getISOCountries() return country codes (uppercase)

like image 13
Arne Burmeister Avatar answered Sep 24 '22 12:09

Arne Burmeister