Java Programming Tutorials

Java programming tutorials with many code examples!

Java Util Currency toString

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

Parameters

The method takes no parameters.

Return value

Returns the ISO 4217 currency code of this currency.

Exceptions

The method throws no exceptions.

Example usage

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

package com.farenda.java.util;

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
Share with the World!