The Currency.getAvailableCurrencies()
method in Java, part of the java.util.Currency
class, is used to retrieve a set of all available currencies.
Table of Contents
- Introduction
getAvailableCurrencies()
Method Syntax- Understanding
getAvailableCurrencies()
- Examples
- Basic Usage
- Listing Currency Codes and Symbols
- Conclusion
Introduction
The getAvailableCurrencies()
method returns a set of all available currencies. This is useful for applications that need to work with multiple currencies and require information about the available currency codes.
getAvailableCurrencies() Method Syntax
The syntax for the getAvailableCurrencies()
method is as follows:
public static Set<Currency> getAvailableCurrencies()
Parameters:
- This method does not take any parameters.
Returns:
- A
Set
ofCurrency
objects representing all the available currencies.
Understanding getAvailableCurrencies()
The getAvailableCurrencies()
method provides a way to retrieve all available currencies recognized by the Java runtime. Each Currency
object in the returned set represents a single currency and provides information such as its currency code and symbol.
Examples
Basic Usage
To demonstrate the basic usage of getAvailableCurrencies()
, we will retrieve the set of available currencies and print their currency codes.
Example
import java.util.Currency;
import java.util.Set;
public class GetAvailableCurrenciesExample {
public static void main(String[] args) {
Set<Currency> currencies = Currency.getAvailableCurrencies();
System.out.println("Available Currencies:");
for (Currency currency : currencies) {
System.out.println(currency.getCurrencyCode());
}
}
}
Output:
Available Currencies:
ERN
CRC
CVE
TOP
AYM
GHS
CYP
BMD
ATS
GYD
DOP
RSD
BTN
VEF
HNL
TMT
MZN
NIO
SLL
BSD
UYU
CLP
CSD
TJS
FKP
RON
VUV
AFA
VES
SDD
INR
SBD
COU
XBC
ANG
GIP
LAK
FIM
LRD
GEL
XPD
CUP
XAG
KYD
RWF
ITL
MRU
SLE
SDG
AZN
XFU
YUM
AMD
MGA
STN
SCR
IQD
KMF
JPY
EUR
MZM
GMD
ZAR
WST
YER
LYD
GRD
IEP
PEN
AOA
MKD
RUB
ISK
EGP
MDL
MXN
ZMW
SEK
KPW
LBP
ZWR
CHF
BAM
ETB
BWP
OMR
TTD
ADP
MVR
SOS
JOD
NZD
CZK
SHP
SRD
JMD
USN
BYR
SIT
NOK
LUF
BGL
NPR
BND
MGF
BRL
BYN
ZWL
LSL
ZWD
MTL
NLG
AED
BBD
PHP
CNY
HKD
HTG
XPT
XFO
USS
GBP
EEK
TRY
BEF
HRK
GHC
PKR
UZS
TWD
SRG
SGD
XBB
LVL
KHR
VND
DEM
MXV
COP
XCD
LKR
CLF
BDT
BGN
VEB
IDR
PAB
XBA
XOF
NAD
ALL
AWG
CAD
XAF
PTE
XDR
MMK
TMM
KWD
XAU
SKK
AUD
MNT
BZD
USD
TZS
DKK
QAR
AFN
ESP
GWP
CUC
ZMK
MYR
XXX
HUF
UAH
BIF
XBD
BOV
ROL
STD
KZT
BHD
ARS
THB
PGK
UYI
KRW
MUR
AZM
MAD
LTL
CHW
SZL
BYB
KES
SVC
XSU
TPE
XUA
ZWN
VED
NGN
DZD
MOP
IRR
FRF
TND
XPF
MRO
XTS
MWK
SYP
SAR
DJF
PYG
PLN
BOB
UGX
RUR
GTQ
ILS
SSP
CDF
GNF
KGS
TRL
CHE
FJD
Listing Currency Codes and Symbols
This example shows how to list both the currency codes and symbols of the available currencies.
Example
import java.util.Currency;
import java.util.Set;
public class CurrencyCodesAndSymbolsExample {
public static void main(String[] args) {
Set<Currency> currencies = Currency.getAvailableCurrencies();
System.out.println("Available Currencies:");
for (Currency currency : currencies) {
System.out.println(currency.getCurrencyCode() + " - " + currency.getSymbol());
}
}
}
Output:
Available Currencies:
ERN - ERN
CRC - CRC
CVE - CVE
TOP - TOP
AYM - AYM
GHS - GHS
CYP - CYP
BMD - BMD
ATS - ATS
GYD - GYD
DOP - DOP
RSD - RSD
BTN - BTN
VEF - VEF
HNL - HNL
TMT - TMT
MZN - MZN
NIO - NIO
SLL - SLL
BSD - BSD
UYU - UYU
CLP - CLP
CSD - CSD
TJS - TJS
FKP - FKP
RON - RON
VUV - VUV
AFA - AFA
VES - VES
SDD - SDD
INR - ?
SBD - SBD
COU - COU
XBC - XBC
ANG - ANG
GIP - GIP
LAK - LAK
FIM - FIM
LRD - LRD
GEL - GEL
XPD - XPD
CUP - CUP
XAG - XAG
KYD - KYD
RWF - RWF
ITL - ITL
MRU - MRU
SLE - SLE
SDG - SDG
AZN - AZN
XFU - XFU
YUM - YUM
AMD - AMD
MGA - MGA
STN - STN
SCR - SCR
IQD - IQD
KMF - KMF
JPY - JP?
EUR - ?
MZM - MZM
GMD - GMD
ZAR - ZAR
WST - WST
YER - YER
LYD - LYD
GRD - GRD
IEP - IEP
PEN - PEN
AOA - AOA
MKD - MKD
RUB - RUB
ISK - ISK
EGP - EGP
MDL - MDL
MXN - MX$
ZMW - ZMW
SEK - SEK
KPW - KPW
LBP - LBP
ZWR - ZWR
CHF - CHF
BAM - BAM
ETB - ETB
BWP - BWP
OMR - OMR
TTD - TTD
ADP - ADP
MVR - MVR
SOS - SOS
JOD - JOD
NZD - NZ$
CZK - CZK
SHP - SHP
SRD - SRD
JMD - JMD
USN - USN
BYR - BYR
SIT - SIT
NOK - NOK
LUF - LUF
BGL - BGL
NPR - NPR
BND - BND
MGF - MGF
BRL - R$
BYN - BYN
ZWL - ZWL
LSL - LSL
ZWD - ZWD
MTL - MTL
NLG - NLG
AED - AED
BBD - BBD
PHP - ?
CNY - CN?
HKD - HK$
HTG - HTG
XPT - XPT
XFO - XFO
USS - USS
GBP - ?
EEK - EEK
TRY - TRY
BEF - BEF
HRK - HRK
GHC - GHC
PKR - PKR
UZS - UZS
TWD - NT$
SRG - SRG
SGD - SGD
XBB - XBB
LVL - LVL
KHR - KHR
VND - ?
DEM - DEM
MXV - MXV
COP - COP
XCD - EC$
LKR - LKR
CLF - CLF
BDT - BDT
BGN - BGN
VEB - VEB
IDR - IDR
PAB - PAB
XBA - XBA
XOF - F?CFA
NAD - NAD
ALL - ALL
AWG - AWG
CAD - CA$
XAF - FCFA
PTE - PTE
XDR - XDR
MMK - MMK
TMM - TMM
KWD - KWD
XAU - XAU
SKK - SKK
AUD - A$
MNT - MNT
BZD - BZD
USD - $
TZS - TZS
DKK - DKK
QAR - QAR
AFN - AFN
ESP - ESP
GWP - GWP
CUC - CUC
ZMK - ZMK
MYR - MYR
XXX - ?
HUF - HUF
UAH - UAH
BIF - BIF
XBD - XBD
BOV - BOV
ROL - ROL
STD - STD
KZT - KZT
BHD - BHD
ARS - ARS
THB - THB
PGK - PGK
UYI - UYI
KRW - ?
MUR - MUR
AZM - AZM
MAD - MAD
LTL - LTL
CHW - CHW
SZL - SZL
BYB - BYB
KES - KES
SVC - SVC
XSU - XSU
TPE - TPE
XUA - XUA
ZWN - ZWN
VED - VED
NGN - NGN
DZD - DZD
MOP - MOP
IRR - IRR
FRF - FRF
TND - TND
XPF - CFPF
MRO - MRO
XTS - XTS
MWK - MWK
SYP - SYP
SAR - SAR
DJF - DJF
PYG - PYG
PLN - PLN
BOB - BOB
UGX - UGX
RUR - RUR
GTQ - GTQ
ILS - ?
SSP - SSP
CDF - CDF
GNF - GNF
KGS - KGS
TRL - TRL
CHE - CHE
FJD - FJD
Conclusion
The Currency.getAvailableCurrencies()
method in Java provides a way to retrieve a set of all available currencies. By using this method, you can dynamically access and process currency information, making it particularly useful for financial applications that need to handle multiple currencies.
Whether you are displaying currency codes, symbols, or both, the getAvailableCurrencies()
method offers a reliable way to access currency data at runtime.
Comments
Post a Comment
Leave Comment