A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.w3resource.com/java-tutorial/util/currency/java_currency_getinstance.php below:

Website Navigation


Java Currency Class: getInstance() Method

Java Currency Class: getInstance() MethodLast update on August 19 2022 21:50:42 (UTC/GMT +8 hours) public static Currency getInstance(Locale locale)

The getInstance() method is used to get the Currency instance for the country of the given locale.

The language and variant components of the locale are ignored. The result may vary over time, as countries change their currencies.
For example, for the original member countries of the European Monetary Union, the method returns the old national currencies until December 31, 2001, and the Euro from January 1, 2002, local time of the respective countries.

Note: The method returns null for territories that don't have a currency, such as Antarctica.

Package: java.util

Java Platform: Java SE 8

Syntax:

getInstance(Locale locale)

Parameters:

Name Description locale   The locale for which a display name for this currency is needed.

Return Value:

The Currency instance for the country of the given locale, or null

Return Value Type: static Currency

Throws:

NullPointerException - if locale or its country code is null

IllegalArgumentException - if the country of the given locale is not a supported ISO 3166 country code.

Example: Java Currency class: getInstance() Method

import java.util.*;

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

      // Create a currency object with given locale 'FRANCE'
      Locale lc = Locale.FRANCE;
      Currency curr = Currency.getInstance(lc);

      // Print currency's code
      System.out.println("Locale's currency code: " + curr.getCurrencyCode());
   }
}

Output:

Locale's currency code:EUR
public static Currency getInstance(String currencyCode)

Returns the Currency instance for the given currency code.

Package: java.util

Java Platform: Java SE 8

Syntax:

getInstance(String currencyCode) 

Parameters:

Name Description currencyCode     the ISO 4217 code of the currency

Return Value:

the Currency instance for the given currency code

Return Value Type: static Currency

Throws:

NullPointerException - if currencyCode is null

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

Example: Java Currency class: getInstance() Method

import java.util.*;
import java.util.*;

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

      // Create a currency object with specified currency code
      Currency curr = Currency.getInstance("ADP");

      // Print currency's code
      System.out.println("Currency code: " + curr.getCurrencyCode());
   }
}

Output:

Currency code: ADP

Java Code Editor:

Previous:getDisplayname Method
Next:getNumericcode Method


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4