獲取國家代碼/名稱鑑於我有貨幣代碼,我如何獲取貨幣適用的國家代碼/名稱?我知道貨幣和國家之間可能會有1:n的映射關係,那麼該如何獲得貨幣適用的所有國家?如何從貨幣代碼
Q
如何從貨幣代碼
1
A
回答
0
爲了獲得貨幣的所有國家,您可以運行一個簡單的搜索到Java中的MultiMap對象。通過在地圖上運行搜索(例如,第一個字符串是貨幣,第二個是國家)以及如果檢查貨幣是否是您要查找的貨幣。如果是這樣,您可以將所有找到的國家添加到數組中,然後進一步使用它們。
0
CurrencyCode
類nv-i18n庫有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.
相關問題
- 1. 如何從iphone中的貨幣代碼獲取貨幣符號?
- 2. 根據貨幣代碼將貨幣格式設置爲貨幣
- 3. iOS如何通過貨幣代碼獲取貨幣符號?
- 4. 是否可以從貨幣代碼中導出貨幣符號?
- 5. 從貨幣代碼中提取貨幣符號Yii
- 6. 從Objective-C中獲取貨幣代碼的貨幣符號
- 7. 如何找出貨幣的html代碼?
- 8. C#格式貨幣給定貨幣代碼(如USD/GBP/FRF)
- 9. 從貨幣代碼中獲取CultureInfo?
- 10. 貨幣代碼返回無
- 11. django國家貨幣代碼
- 12. 如何在貨幣符號中更改貨幣代碼縮寫Magento
- 13. 如何將貨幣符號轉換爲iOS中的貨幣代碼?
- 14. 轉換成ISO 4217的數字貨幣代碼貨幣名稱
- 15. 3位貨幣代碼到貨幣符號
- 16. 根據ISOCountryCode獲取貨幣符號和貨幣代碼
- 17. 在magento顯示貨幣代碼和貨幣符號
- 18. 如何從貨幣代碼中獲取NumberFormat實例?
- 19. 如何使用Apache POI從Excel中獲取貨幣代碼?
- 20. 如何從priceLocale獲取貨幣代碼(樣本120¥)?
- 21. 如何從貨幣代碼中獲取NSLocale?
- 22. 如何代表貨幣或貨幣使用C
- 23. 如何從NumberFormat的貨幣especific改變爲美元貨幣
- 24. 從貨幣
- 25. 貨幣掩碼jqgrid
- 26. 在線貨幣交易.. php代碼
- 27. 商店貨幣代碼以及價格
- 28. 貨幣符號和代碼動態
- 29. 貨幣代碼是在Xcode ES-419
- 30. 經由代碼在C#改變貨幣
您可以在貨幣/國家組合存儲在數據庫中的表。當財務狀況發生變化時,您需要更新表格。 – 2015-04-06 11:08:08
不想自己維護映射。這不是一些API嗎? – akrohit 2015-04-06 11:09:19