Home » Java programming language

Java Currency getCurrencyCode() Method with Example

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

Currency Class getCurrencyCode() method

  • getCurrencyCode() method is available in java.util package.
  • getCurrencyCode() method is used to get the ISO 4217 currency code of this Currency.
  • getCurrencyCode() method is a non-static method, so it is accessible with the class object and if we try to access the method with the class name then we will get an error.
  • getCurrencyCode() method does not throw an exception at the time of returning currency code.

Syntax:

    public String getCurrencyCode();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of this method is String, it returns ISO 4217 currency code of this Currency object.

Example:

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

import java.util.*;

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

        // By using getCurrencyCode() method is 
        // to get the currency code of this Currency

        String curr_code = currency.getCurrencyCode();
        System.out.println("currency.getCurrencyCode(): " + curr_code);
    }
}

Output

currency.getCurrencyCode(): INR


Comments and Discussions!

Load comments ↻





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