获取所有可能的可用货币 [英] Get All Possible Available Currencies

查看:84
本文介绍了获取所有可能的可用货币的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得所有可能的货币。

I would like to get all possible available currencies.

Java 7提供了这样的功能。

Java 7 had provided such feature.

public static Set<java.util.Currency> java.util.Currency.getAvailableCurrencies()

但是,我仍在使用Java 6进行开发和部署。我可以知道如何获得所有可能的货币吗?代码示例最受欢迎。

However, I am still using Java 6 for development and deployment. May I know how I can get all possible available currencies? Code example are most welcomed.

推荐答案

在研究了ISO表和货币类文档后,您似乎可以要求货币作为代码或Locale;并且Locale类有一个 getAvailableLocales()方法。

After studying the ISO table and the Currency class documentation, it seems that you can ask for currency as code or as Locale; and the class Locale has a getAvailableLocales() method.

所以代码是:

    public static Set<Currency> getAllCurrencies()
    {
        Set<Currency> toret = new HashSet<Currency>();
        Locale[] locs = Locale.getAvailableLocales();

        for(Locale loc : locs) {
            try {
                Currency currency = Currency.getInstance( loc );

                if ( currency != null ) {
                    toret.add( currency );
                }
            } catch(Exception exc)
            {
                // Locale not found
            }
        }

        return toret;
    }

希望这有帮助。

这篇关于获取所有可能的可用货币的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆