Java.util.Currency.toString() Method



Description

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

Declaration

Following is the declaration for java.util.Currency.toString() method

public String toString()

Parameters

NA

Return Value

This method returns the currency's ISO 4217 code

Exception

NA

Example

The following example shows the usage of java.util.Currency.toString() method.

package com.tutorialspoint;

import java.util.*;

public class CurrencyDemo {
   public static void main(String[] args) {

      // create a currency with specified currency code
      Currency curr = Currency.getInstance("USD");

      // get the currency string and print it
      System.out.println("String representation:" + curr.toString());
   }
}

Let us compile and run the above program, this will produce the following result −

String representation:USD
java_util_currency.htm
Advertisements