Java Currency getAvailableCurrencies() Method



Description

The Java Currency getAvailableCurrencies() method gets the set of all the available currencies. These currencies may include currencies that represent obsolete ISO 4217 codes. The set is modifiable and can be modified without affecting the available currencies in the runtime.

Declaration

Following is the declaration for java.util.Currency.getAvailableCurrencies() method

public static Set<Currency> getAvailableCurrencies()

Parameters

NA

Return Value

This method returns the set of available currencies. If there is no currency available in the runtime, the returned set is empty.

Exception

NA

Getting Available Currencies and Iterating them Example

The following example shows the usage of Java Currency getAvailableCurrencies() method to get a set of available currencies. We've created a set of avaiable currencies using getAvailableCurrencies() method and then printed each currency code.

package com.tutorialspoint;

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

public class CurrencyDemo {
   public static void main(String args[]) {

      Set<Currency> currencies = Currency.getAvailableCurrencies();

      System.out.println("Available Currencies: ");
      currencies.forEach(c -> System.out.print(c.getCurrencyCode() + " "));
   }
}

Output

Let us compile and run the above program, this will produce the following result −

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