Currency toString() Method in Java with Examples Last Updated : 27 Dec, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report The toString() Method of Currency class in Java is used to retrieve the currency code of this currency which is actually the official ISO 4217 currency code in a string format Syntax: CURRENCY.toString() Parameters: This method does not accept any parameters. Return Value: This method returns the ISO 4217 currency code of the currency. Exceptions: The method throws Runtime Error if an invalid code is called. Below program illustrates the working of toString() method: Program 1: Java // Java Code to illustrate toString() method import java.util.*; public class Currency_Demo { public static void main(String[] args) { // Creating a currency with the code Currency curr_ency = Currency.getInstance("INR"); // Getting the currency code String currency_code = curr_ency.toString(); System.out.println("Currency Code of India is: " + currency_code); } } Output: Currency Code of India is: INR Program 2: Java // Java Code to illustrate toString() method import java.util.*; public class Currency_Demo { public static void main(String[] args) { // Creating a currency with the code Currency curr_ency = Currency.getInstance("USD"); // Getting the currency code String currency_code = curr_ency.toString(); System.out.println("Currency Code of USA is: " + currency_code); } } Output: Currency Code of USA is: USD Program 3: For an invalid Currency Code. Java // Java Code to illustrate toString() method import java.util.*; public class Currency_Demo { public static void main(String[] args) { try { // Creating a currency with the code Currency curr_ency = Currency.getInstance("USDA"); // Getting the currency code String currency_code = curr_ency.toString(); System.out.println("Invalid Currency Code: " + currency_code); } catch (Exception e) { System.out.println(e); } } } Output: java.lang.IllegalArgumentException Comment More infoAdvertise with us Next Article Currency toString() Method in Java with Examples C chinmoy lenka Follow Improve Article Tags : Misc Java Java - util package Java-Functions Java-Currency +1 More Practice Tags : JavaMisc Similar Reads Charset toString() method in Java with Examples The toString() method is a built-in method of the java.nio.charset returns a string which describes the charset involved. Syntax: public final String toString() Parameters: The function does not accepts any parameter. Return Value: The function returns a string describing this charset. Below is the 1 min read Duration toString() method in Java with Examples The toString() method of Duration Class in java.time package is used to get the String value of this duration. This String is in the ISO-8601 format. Syntax: public String toString() Parameters: This method do not accepts any parameter. Return Value: This method returns a String value which is the S 1 min read Byte toString() method in Java with examples The toString() method of Byte class is a built in method in Java which is used to return a String value. public String toString() Syntax: ByteObject.toString() Return Value: It returns a String object, the value of which is equal to the value of the ByteObject. Below is the implementation of toStrin 2 min read Class toString() method in Java with Examples The toString() method of java.lang.Class class is used to convert the instance of this Class to a string representation. This method returns the formed string representation. Syntax: public String toString() Parameter: This method does not accept any parameter. Return Value: This method returns the 1 min read Bidi toString() method in Java with Examples The toString() method of java.text.Bidi class is used to display this Bidi instance in string representation. Syntax: public String toString() Parameter: This method accepts nothing as parameter. Return Value: This method display internal state of bidi in string format. Below are the examples to ill 2 min read Like