当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java Currency getAvailableCurrencies()用法及代码示例


getAvailableCurrencies() 是 Java Currency 类的一个方法,用于获取可用货币集。它返回所有货币,其中可能包括代表过时 ISO 4217 代码的货币。

用法

以下是 getAvailableCurrencies() 方法的声明:

Public static Set<Currency> getAvailableCurrencies()

参数

数据类型 参数 描述
静态集 NA 它将所有可用货币作为 Set 对象返回

返回

getAvailableCurrencies() 方法返回货币集。在运行时,如果没有可用的货币,这将返回空集。

异常

NA

兼容版本

Java 1.7 及以上

例子1

import java.util.Currency;
import java.util.Set;
public class CurrencyGetAvailableCurrenciesExample1 {
   public static void main(String args[]) {
     Set<Currency> currencySet =  Currency.getAvailableCurrencies();
     System.out.println("Available currencies are:");
     for(Currency c:currencySet){
       System.out.println(c);
     }
   }
}

输出:

Available currencies are:
ETB
CRC
CVE
TMT
ADP
GIP
COU
BGN
ZWL

例子2

import java.util.Currency;
import java.util.Set;
public class CurrencyGetAvailableCurrenciesExample2 { 
    public static void main(String[] args) {        
        Set<Currency> currencySet = Currency.getAvailableCurrencies();
        System.out.println("\nTotal Number of available Currencies is:"+currencySet.size()); 
        }
    }

输出:

Total Number of available Currencies is:224

例子3

import java.util.Set;
import java.util.Currency;
public class CurrencyGetAvailableCurrenciesExample3 {
    public static void main(String[] args) {
        Set<Currency> currencySet = Currency.getAvailableCurrencies();
        System.out.println("List of all currencies are:\n ")
        for (Currency currency:currencySet) {
            // print the currencies horizontally:
                System.out.print(currency+", ");
        }
    }
}

输出:

List of all currencies are:
ETB, CRC, CVE, TMT, ADP, GIP, COU, BGN, ZWL, HKD, DOP, QAR, BOB, XAU, HRK, THB, MYR, NIO, 
SKK, BND, UAH, CLP, CSD, SZL, GBP, PYG, UZS, ZMW, USD, RUR, INR, RWF, CHW, XCD, GMD, LAK, 
EEK, LRD, GHS, XPD, CUP, XBA, KYD, RSD, GWP, MOP, SGD, SBD, AOA, XOF, XXX, MDL, SRD, SAR, 
IQD, KMF, JPY, MXV, GNF, VUV, VEF, VND, LYD, FIM, GRD, OMR, AED, MGA, RON, ISK, EGP, MAD, 
MWK, WST, SCR, KPW, ZWR, LBP, ZWN, CDF, ARS, FJD, BSD, NPR, TOP, ZAR, MUR, SHP, JOD, CHF, 
CZK, SEK, SLL, JMD, USS, BGL, SDD, BRL, ITL, AYM, NOK, BHD, LUF, BMD, BTN, YER, LSL, ZMK, 
MGF, MZM, AUD, PEN, CNY, HNL, HTG, XPF, XFU, UYI, GEL, CYP, TND, ATS, GHC, EUR, PGK, UGX, 
TRY, SRG, SDG, XBD, LTL, KHR, UYU, CUC, MTL, COP, LKR, CHE, AWG, BAM, XAF, IDR, NZD, XBC, 
AZN, MZN, ANG, BYR, CAD, NLG, XFO, MKD, TPE, KWD, XBB, SIT, AMD, MMK, BWP, ALL, TTD, DKK, 
PLN, DEM, FRF, CLF, YUM, MXN, XUA, HUF, TWD, BDT, XDR, AZM, PTE, TMM, KZT, BBD, AFN, SYP, 
PAB, VEB, KRW, MRO, AFA, ERN, IEP, BYB, SVC, BEF, KES, SSP, XPT, TRL, XTS, ZWD, XAG, NGN, 
DZD, MNT, IRR, ESP, TJS, NAD, LVL, XSU, MVR, STD, RUB, DJF, PKR, PHP, BIF, TZS, ROL, GYD, 
ILS, SOS, BZD, GTQ, KGS, USN, BOV, FKP,

示例 4

import java.util.Currency;
import java.util.Set;
public class CurrencyGetAvailableCurrenciesExample4 {
    public static void main(String[] args) {        
        Set<Currency> currencySet = Currency.getAvailableCurrencies();
        for (Currency currency:currencySet) {
            // print the currency with name:
            	System.out.println("Currency:"+currency +" Name:"+currency.getDisplayName());
        }
    }
}

输出:

Currency:ETB Name:Ethiopian Birr
Currency:CRC Name:Costa Rican Colรณn
Currency:CVE Name:Cape Verdean Escudo
Currency:TMT Name:Turkmenistani Manat
Currency:ADP Name:Andorran Peseta
Currency:GIP Name:Gibraltar Pound
Currency:COU Name:COU
Currency:BGN Name:Bulgarian Lev
Currency:ZWL Name:Zimbabwean Dollar (2009)
Currency:HKD Name:Hong Kong Dollar
Currency:DOP Name:Dominican Peso



相关用法


注:本文由纯净天空筛选整理自 Java Currency getAvailableCurrencies() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。