java.util.Currency getSymbol()

Description

The getSymbol() method of Currency class is use to get the symbol of this currency for the default DISPLAY locale. One notable example is for the currency of the US which is the US Dollar, the symbol is “$” if the default locale is the US, meanwhile for other locales it may be “US$” or sometimes “USD”. If no symbol can be determined, the ISO 4217 currency code is returned. This method is basically in place to take into consideration different values of each symbol on each Locale, because different countries has different currency symbol that is being used with respect to currency of other countries.

This is equivalent to calling getSymbol(Locale.getDefault(Locale.Category.DISPLAY)). As a reference the getSymbol method is overloaded which means that this method has more than one method implementation but with different method signature. One of the overloaded method is a getSymbol() without a method argument which we currently discussing, meanwhile the other overloaded method takes an argument Locale.

Method Syntax

public String getSymbol()

Method Argument

Data Type Parameter Description
N/A N/A N/A

Method Returns

The getSymbol() method of Currency class returns the symbol of this currency for the default DISPLAY locale.

Compatibility

Java 1.4

Java Currency getSymbol() Example

Below is a simple java example on the usage of getSymbol() method of Currency class.

package com.javatutorialhq.java.examples;

import static java.lang.System.*;

import java.util.Currency;


/*
 * This example source code demonstrates the use of 
 * getSymnbol() method of Currency class.
 */

public class CurrencyGetSymbolExample {

	public static void main(String[] args) {

		// create an instance of Currency class
		Currency currency = Currency.getInstance("JPY");
		// get the symbol for Japanese Yen
		out.println("Symbol of JPY in the current locale:" +
				currency.getSymbol());
	}
}

Basically on the above example, we just created a new Currency object with currency code of JPY with the intention of printing the currency symbol used for Japanese Yen using the getSymbol() method.

Sample Output

Below is the sample output when you run the above example.

Currency getSymbol() Sample Output