java.util.Currency getAvailableCurrencies()

Description

The getAvailableCurrencies() method of Currency class is use to get the set of available currencies. The returned set of currencies contains all of the available currencies, which may include currencies that represent obsolete ISO 4217 codes. The set can be modified without affecting the available currencies at runtime.

Method Syntax

public static Set<Currency> getAvailableCurrencies()

Method Argument

Data Type Parameter Description
N/A N/A N/A

Method Returns

The getAvailableCurrencies() method of Currency class returns the set of available currencies. If there is no currency available in the runtime, the returned set is empty.

Compatibility

Java 1.7

Discussion

The method getAvailableCurrencies() is a convenient way to get all the available Currency on the system and from there we can select which is appropriate to use or maybe the result can be used for catching exceptions. This method is also very useful to those programmers who have not yet used the Currency API since this method enumerating all possible Currency and their values which can greatly help to evaluate and design our requirements.

Java Currency getAvailableCurrencies() Example

Below is a simple java example on the usage of floatToIntBits(float value) method of Float class.

package com.javatutorialhq.java.examples;


import static java.lang.System.*;

import java.util.Currency;
import java.util.Set;

/*
 * This example source code demonstrates the use of 
 * getAvailableCurrencies() method of Currency class.
 */

public class CurrencyGetAvailableCurrenciesExample {

	public static void main(String[] args) {
		
		// get the available currency on our system
		Set currencySet  = Currency.getAvailableCurrencies();
		// list all currency available on the set
		for(Currency currency:currencySet){
			System.out.println(currency.getDisplayName());
			
		}		
	}
}

Basically on the above example, we just get a set of available currencies and we iterate through each element printing all the currency display names.

Sample Output

Below is the sample output when you run the above example.

Currency getAvailableCurrencies() Sample Output