Example usage for java.util Locale getISOCountries

List of usage examples for java.util Locale getISOCountries

Introduction

In this page you can find the example usage for java.util Locale getISOCountries.

Prototype

public static String[] getISOCountries() 

Source Link

Document

Returns a list of all 2-letter country codes defined in ISO 3166.

Usage

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    String[] countries = Locale.getISOCountries();

    System.out.println("Countries:\n");
    for (int i = 0; i < countries.length; i++)
        System.out.println(countries[i]);
}

From source file:CountryLanguageCodes.java

public static void main(String[] argv) {

    String[] countries = Locale.getISOCountries();
    String[] languages = Locale.getISOLanguages();
    int i;//  w  ww  .j  av  a 2s .  c om

    System.out.println("\nCountries:\n");
    for (i = 0; i < countries.length; i++)
        System.out.println(countries[i]);
    System.out.println("\nLanguages:\n");
    for (i = 0; i < languages.length; i++)
        System.out.println(languages[i]);
}

From source file:Main.java

public static void main(String[] args) {
    Locale locale = new Locale("en", "US", "WIN");

    System.out.println("Locale:" + locale);

    // get ISO countries
    String[] countries = Locale.getISOCountries();

    // print countries
    System.out.println("Countries are:");
    for (int i = 0; i < countries.length; i++) {
        System.out.println(i + ":" + countries[i]);
    }//from   w  ww. jav  a  2 s.  c o  m
}

From source file:Main.java

public static String getCountryCode(String spinnerText) {
    String[] locales = Locale.getISOCountries();
    ArrayList<String> countries = new ArrayList<>();
    for (String countryCode : locales) {

        Locale locale = new Locale("", countryCode);
        try {// w  ww  . j  a  v  a 2 s  .  c o  m
            Currency currency = Currency.getInstance(locale);
            String proposedSpinnerText = locale.getDisplayCountry() + " (" + currency.getCurrencyCode() + ")";

            if (proposedSpinnerText.equals(spinnerText)) {
                return countryCode;
            }
        } catch (Exception e) {

        }
    }
    return "";
}

From source file:Main.java

public static ArrayList<String> getCountriesArray() {
    String[] locales = Locale.getISOCountries();
    ArrayList<String> countries = new ArrayList<String>();
    for (String countryCode : locales) {

        Locale locale = new Locale("", countryCode);
        try {/*  w w  w.  j a  v  a 2 s  .com*/
            Currency currency = Currency.getInstance(locale);
            countries.add(locale.getDisplayCountry() + " (" + currency.getCurrencyCode() + ")");
        } catch (Exception e) {

        }
    }
    Collections.sort(countries);
    return countries;
}

From source file:Main.java

private static Map<String, String> initCountries() {
    Map<String, String> countries = new HashMap<String, String>();
    for (String iso : Locale.getISOCountries()) {
        Locale l = new Locale(loc, iso);
        countries.put(l.getDisplayCountry(), iso);
    }//from   w  w  w  .  j av  a 2  s. co  m
    return countries;
}

From source file:Main.java

public static void setCountriesISOMap() {
    String[] isoCountryCodes = Locale.getISOCountries();
    for (int i = 0; i < isoCountryCodes.length; i++) {
        Locale locale = new Locale("", isoCountryCodes[i]);
        countriesISOMap.put(locale.getDisplayCountry(), isoCountryCodes[i]);
    }//from   www  .j  a  v  a  2  s  .  c o  m
}

From source file:org.openestate.io.core.LocaleUtils.java

/**
 * Return an ISO-2 country code from a country name.
 *
 * @param country//ww w .  j a  va2  s  .c om
 * country name
 *
 * @return
 * ISO-2 country code or null, if no code was found
 */
public static String getCountryISO2(String country) {
    country = StringUtils.trimToNull(country);
    if (country == null)
        return null;
    if (country.length() == 2)
        return country;

    String[] iso2Codes = Locale.getISOCountries();
    if (country.length() == 3) {
        String iso2Code = LocaleUtils.getCountryISO2FromISO3(country);
        if (iso2Code != null)
            return iso2Code;
    }

    for (String iso2Code : iso2Codes) {
        Locale countryLocale = new Locale(iso2Code, iso2Code);
        for (Locale translationLocale : LocaleUtils.availableLocaleList()) {
            String name = StringUtils.trimToNull(countryLocale.getDisplayCountry(translationLocale));
            if (name != null && name.equalsIgnoreCase(country))
                return iso2Code;
        }
    }
    return null;
}

From source file:com.carlomicieli.jtrains.validation.ISOValidationUtils.java

/**
 * Returns {@code true} if the value is a valid 2-letter country code as defined in ISO 3166.
 * @param country the country code/*from   w  w w  .  j a va2  s .c o m*/
 * @return {@code true} if the value is a valid country; {@code false} otherwise
 */
public static boolean countryIsValid(String country) {
    if (StringUtils.isBlank(country)) {
        return true;
    }
    return Arrays.binarySearch(Locale.getISOCountries(), country.toUpperCase()) >= 0;
}

From source file:ListOfCitys.CityList.java

private static String getCountryName(String zone) throws IOException {
    String[] arry = zone.split(";"); //EU;DE
    zone = arry[1];/*from ww w .j a va2s .c  om*/
    String[] locales = Locale.getISOCountries();
    String countryName = "";
    JSONArray countryWithCities = new JSONArray();
    Map<String, List<String>> countryWithCityNames = new HashMap<>();
    for (String countryCode : locales) {
        Locale obj = new Locale("", countryCode);
        System.out
                .println("Country Code = " + obj.getCountry() + ", Country Name = " + obj.getDisplayCountry());
        countryWithCities.add(getCityNameForCountry(obj.getCountry(), countryCode));
        if (obj.getCountry().equalsIgnoreCase(zone)) {
            countryName = obj.getDisplayCountry();
            break;
        }
    }
    System.out.println("-----json array --- " + countryWithCities.toJSONString());
    try (FileWriter file = new FileWriter("test.json")) {
        file.write(countryWithCities.toJSONString());
    }
    return countryName;
}