public static String getCountryISO3 ( String country ) { country = StringUtils . trimToNull ( country ) ; if ( country == null ) return null ; if ( country . length ( ) == 3 ) return country ; String [ ] iso2Codes = Locale . getISOCountries ( ) ; if ( country . length ( ) == 2 ) { String iso3code = LocaleUtils . getCountryISO3FromISO2 ( country ) ; if ( iso3code != null ) return iso3code ; } for ( String iso2Code : iso2Codes ) { Locale countryLocale = new Locale ( iso2Code , iso2Code ) ; String iso3Code = StringUtils . trimToNull ( countryLocale . getISO3Country ( ) ) ; if ( iso3Code == null ) continue ; for ( Locale translationLocale : LocaleUtils . availableLocaleList ( ) ) { String name = StringUtils . trimToNull ( countryLocale . getDisplayCountry ( translationLocale ) ) ; if ( name != null && name . equalsIgnoreCase ( country ) ) return iso3Code ; } } return null ; }
Return an ISO - 3 country code from a country name .