java.util.Currency.getInstance(String currencyCode)
The method java.util.Currency.getInstance(String currencyCode) returns the Currency instance for the given currency code.
Method signature
The signature of the java.util.Currency.getInstance(String currencyCode) method is as follows:
public static Currency getInstance(String currencyCode)
Parameters
- currencyCode: the ISO 4217 code of the currency
Return value
Returns the Currency instance for the given currency code.
Exceptions
- NullPointerException: if currencyCode is null
- IllegalArgumentException: if currencyCode is not a supported ISO 4217 code
Example usage
In the following code we use java.util.Currency.getInstance(String currencyCode):
package com.farenda.java.util; import java.util.Currency; public class CurrencyGetInstanceString { public static void main(String[] args) { String name = "USD"; Currency currency = Currency.getInstance(name); System.out.printf("Currency of %s: %s%n", name, currency.getDisplayName()); name = "XXX"; currency = Currency.getInstance(name); System.out.printf("Currency of %s: %s%n", name, currency); } }
The above code produces the following output:
Currency of USD: US Dollar Currency of XXX: XXX