w3resource

Java Currency Class: getDisplayName() Method

public String getDisplayName()

The getDisplayName() method is used to get the name that is suitable for display a given currency for the default DISPLAY locale.

If there is no suitable display name found for the default locale, the ISO 4217 currency code is returned.

Note: The method is equivalent to calling getDisplayName(Locale.getDefault(Locale.Category.DISPLAY)).

Package: java.util

Java Platform: Java SE 8

Syntax:

getDisplayName()

Return Value:

The display name of this currency for the default DISPLAY locale

Return Value Type: String

Example: Java Currency class: getDisplayName() Method

The following example fills a Java Currency class: getDisplayName() Method.

import java.util.*;

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

      // Create 2  currencies
      Currency cr1 = Currency.getInstance("AUD"); //Australian Dollar
      Currency cr2 = Currency.getInstance("USD");  //Japan Yen

      //Display currencY using getDisplayName() method
      System.out.println("AUD Display : "+cr1.getDisplayName());
      System.out.println("USD Display : "+cr2.getSymbol());
     }
}

Output:

AUD Display : Australian Dollar
USD Display : $

public String getDisplayName(Locale locale)

Gets 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.

Package: java.util

Java Platform: Java SE 8

Syntax:

getDisplayName(Locale locale)

Parameters:

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

Return Value:

The display name of this currency for the specified locale.

Return Value Type: String

Example: Java Currency class: getDisplayName() Method

The following example fills a Java Currency class: getDisplayName() Method.

import java.util.*;

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

      // Create a currency for GERMANY locale
      Locale locale = Locale.GERMANY;
      Currency cur1 = Currency.getInstance(locale);

      // Get and print the symbol of the currency
      String symbol = cur1.getDisplayName(locale);
      System.out.println("Display name: " + symbol);
   }
}

Output:

Display name: Euro

Java Code Editor:

Previous:getDefaultfractiondigits Method
Next:getInstance Method



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/java-tutorial/util/currency/java_currency_getdisplayname.php