Java Currency.getInstance(String currencyCode)

 Posted On  | Yashwant Chavan 

In this tutorial, You will learn about Java Currency.getInstance(String currencyCode) Method. Which returns the Currency instance for the given currency code.

syntax

Returns the Currency instance for the given currency code.

Currency java.util.Currency.getInstance(String currencyCode)

Paramters

currencyCode the ISO 4217 code of the currency.

Return

return the Currency instance for the given currency code.

Exceptions

NullPointerException - if currencyCode is null

IllegalArgumentException - if currencyCode is not a supported ISO 4217 code.

Java Currency.getCurrencyCode() example

Refer below steps

  • Create Currency instance using Currency.getInstance(Locale locale) method.
  • Print currency code using Currency.getCurrencyCode() method.
package com.technicalkeeda.app;

import java.util.Currency;

public class JavaCurrencyGetInstance {

    public static void main(String[] args) {

        Currency us = Currency.getInstance("USD");
        System.out.println("Currency code US:- " + us);

        Currency gbp = Currency.getInstance("GBP");
        System.out.println("Currency code GBP:- " + gbp);

    }
}

Output

Currency code US:- USD
Currency code GBP:- GBP


Promote your Blog, Website, or services on technicalkeeda.com, My paypal id: yashwantchavan@gmail.com

Payment will be accepted through paypal only.


© technicalkeeda.com 2017

 |  Find us on Google+ |  Rss Feed

Loaded in 0.0299 seconds.