Programming for fun and profit

Programming tutorials, problems, solutions. Always with code.

Java Util Currency getCurrencyCode


The method java.util.Currency.getCurrencyCode() gets the ISO 4217 currency code of this currency.

Method signature

The signature of the java.util.Currency.getCurrencyCode() method is as follows:

public String getCurrencyCode()


The method takes no parameters.

Return value

Returns the ISO 4217 currency code of this currency.


The method throws no exceptions.

Example usage

In the following code we use java.util.Currency.getCurrencyCode():


import java.util.Currency;
import java.util.Locale;

public class CurrencyCurrencyCode {

    public static void main(String[] args) {
        Locale locale = Locale.CHINA;
        Currency currency = Currency.getInstance(locale);
        //ISO 4217 code:
        System.out.println("Currency code: "
                + currency.getCurrencyCode());

        currency = Currency.getInstance(Locale.CANADA_FRENCH);
        System.out.println("Currency code: "
                + currency.getCurrencyCode());

The above code produces the following output:

Currency code: CNY
Currency code: CAD
Share with the World!