Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

import java.util.Currency;

import java.util.Locale;

public class Main {
    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 {
                Currency currency = Currency.getInstance(locale);
                String proposedSpinnerText = locale.getDisplayCountry() + " (" + currency.getCurrencyCode() + ")";

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

            }
        }
        return "";
    }
}