Java Utility Library

Java Currency - getDisplayName() Method



The java.util.Currency.getDisplayName() method returns the name that is suitable for displaying this currency for the specified locale. If there is no suitable display name found for the specified locale, the ISO 4217 currency code is returned.

Syntax

public String getDisplayName(Locale locale)

Parameters

locale Specify the locale for which a display name for this currency is needed.

Return Value

Returns the display name of this currency for the specified locale.

Exception

Throws NullPointerException, if locale is null.

Example:

In the example below, the java.util.Currency.getDisplayName() method is used to get the name of the currency using the specified locale.

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //creating a currency for UK locale
    Locale locale = Locale.UK;
    Currency Curr = Currency.getInstance(locale);

    //getting and printing the name of the 
    //currency using the Germany locale
    String CurrName = Curr.getDisplayName(Locale.GERMANY);
    System.out.println("Currency Name: " + CurrName);
  }
}

The output of the above code will be:

Currency Name: Britisches Pfund

❮ Java.util - Currency