Java Programming Tutorials

Java programming tutorials with many code examples!

Java Util Currency toString


The method java.util.Currency.toString() overrides Object.toString() and returns the ISO 4217 currency code of this currency.

Method signature

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

public String toString()

It overrides Object.toString().


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.toString():


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

public class CurrencyToString {

    public static void main(String[] args) {
        // For Chinese Yuan:
        Locale locale = Locale.CHINA;
        Currency currency = Currency.getInstance(locale);
        System.out.println("Currency toString(): "
                + currency.toString());

        // For Euro currency:
        currency = Currency.getInstance("EUR");
        System.out.println("Currency toString(): "
                + currency.toString());

The above code produces the following output:

Currency toString(): CNY
Currency toString(): EUR
Was it helpful? Share!