Get All Possible Available Currencies

前端 未结 8 1647
忘了有多久
忘了有多久 2021-02-05 09:17

I would like to get all possible available currencies.

Java 7 had provided such feature.

public static Set java.util.Currency.g         


        
8条回答
  •  臣服心动
    2021-02-05 09:44

    Otherwise a version a little better of Baltasarq code to avoid duplication:

        ArrayList currencys = new ArrayList();
        Locale[] locs = Locale.getAvailableLocales();
    
        for(Locale loc : locs) {
            try {
                String val=Currency.getInstance(loc).getCurrencyCode();
                if(!currencys.contains(val))
                    currencys.add(val);
            } catch(Exception exc)
            {
                // Locale not found
            }
            Collections.sort(currencys);
        }
    

    I have tested on android.

提交回复
热议问题