gpt4 book ai didi

java - 如何从货币代码中获取国家代码/名称

转载 作者:太空狗 更新时间:2023-10-29 14:10:21 32 4
gpt4 key购买 nike

鉴于我有货币代码,我如何获得适用于该货币的国家/地区代码/名称?我了解货币和国家/地区之间可能存在 1:n 映射,在这种情况下,如何获取适用该货币的所有国家/地区?

最佳答案

nv-i18n 中的

CurrencyCode 类库有 getCountryList() 方法,它返回使用该货币的国家列表。下面是一个示例命令行应用程序。

import java.util.List;
import com.neovisionaries.i18n.CountryCode;
import com.neovisionaries.i18n.CurrencyCode;

public class CurrencyToCountryList
{
public static void main(String[] args)
{
// For each currency code such as EUR and USD.
for (String code : args)
{
// Get a CurrencyCode instance.
CurrencyCode currency =
CurrencyCode.getByCode(code);

if (currency == null)
{
// The code is invalid.
System.out.format("'%s' is invalid.\n", code);
continue;
}

System.out.format("%s (%s) is used by:\n",
currency, currency.getName());

// Get the list of countries using the currency.
List<CountryCode> countryCodeList =
currency.getCountryList();

// For each country.
for (CountryCode country : countryCodeList)
{
// Print the country code and the country name.
System.out.format("\t%s: %s\n",
country, country.getName());
}
}
}
}

如果你像这样运行这个应用程序:

$ java -cp nv-i18n-1.15.jar:. CurrencyToCountryList USD

您将得到如下所示的结果:

USD (US Dollar) is used by:
AS: American Samoa
BQ: Bonaire, Sint Eustatius and Saba
EC: Ecuador
FM: Micronesia, Federated States of
GU: Guam
HT: Haiti
IO: British Indian Ocean Territory
MH: Marshall Islands
MP: Northern Mariana Islands
PA: Panama
PR: Puerto Rico
PW: Palau
SV: El Salvador
TC: Turks and Caicos Islands
TL: Timor-Leste
UM: United States Minor Outlying Islands
US: United States
VG: Virgin Islands, British
VI: Virgin Islands, U.S.

关于java - 如何从货币代码中获取国家代码/名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29470019/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com