Home » Java programming language

Java Currency toString() Method with Example

Currency Class toString() method: Here, we are going to learn about the toString() method of Currency Class with its syntax and example.
Submitted by Preeti Jain, on February 12, 2020

Currency Class toString() method

  • toString() method is available in java.util package.
  • toString() method is for the string representation of this Currency.
  • toString() method is a non-static method, it is accessible with the class object and if we try to access these methods with the class name then we will get an error.
  • toString() method does not throw an exception at the time of the string representation of this currency.

Syntax:

    public int toString();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of this method is String, it returns this currency in string form.

Example:

// Java program is to demonstrate the example of
// toString() method of Currency

import java.util.*;

public class ToStringOfCurrency {
    public static void main(String args[]) {
        // Instantiates a currency with INR code
        Currency currency = Currency.getInstance("INR");

        // By using toString() method is to represent
        // the currency as a string
        System.out.print("currency.toString(): ");
        System.out.println(currency.toString());
    }
}

Output

currency.toString(): INR


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.