Get/Find All Possible Currencies Using Java API

In this example we are generating all possible currencies using Java.
Locale.getAvailableLocales()
The method Locale.getAvailableLocales() returns the array of Locale values. We can iterate this array of Locale and able to view the different countries available as per the Locale.
We can also use Currency.getInstance(locale).getCurrencyCode() method to find the currency code for each country
Get/Find all possible currencies using Java
package com.test;
import java.util.Currency;
import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;
public class FindAllCurrencyInJava {
public static void main(String[] args) {
//Find All the possible currencies using Java API
Map<String, String> currencies = new TreeMap<String, String>();
for (Locale locale : Locale.getAvailableLocales()) {
try {
currencies.put(locale.getDisplayCountry(), Currency.getInstance(locale).getCurrencyCode());
} catch (Exception e) {
// when the locale is not supported
}
}
System.out.println("Total Available currencies "+currencies);
}
}
import java.util.Currency;
import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;
public class FindAllCurrencyInJava {
public static void main(String[] args) {
//Find All the possible currencies using Java API
Map<String, String> currencies = new TreeMap<String, String>();
for (Locale locale : Locale.getAvailableLocales()) {
try {
currencies.put(locale.getDisplayCountry(), Currency.getInstance(locale).getCurrencyCode());
} catch (Exception e) {
// when the locale is not supported
}
}
System.out.println("Total Available currencies "+currencies);
}
}