Java Currency getInstance() MethodThere are two types of getIsntance methods. Java Currency getInstance(Loacale locale) MethodThe getInstance(Locale locale) is the method of Java Currency class which is used to get an instance of currency for the given country. Because countries change their currencies, the result may vary over time. SyntaxFollowing is the declaration of getInstance() method: Parameter
ReturnsThis method will return the instance of Currency for the given locale of country, or it will return null. ExceptionsNullPointerException - If locale or currencyCode is null. IllegalArgumentException ? If the country of locale is not a supported ISO 3166 country code. Compatibility VersionJava 1.4 and above Example 1Output: Currency code of given locale: EUR Example 2Output: Currency code UK = GBP Currency code US = USD Example 3Output: Currency code is: EUR Example 4Output: ---------Indian Currency---------- Currency display name : Indian Rupee Currency Code : INR Currency Numeric Code : 356 Java Currency getInstance(String currencyCode) MethodThe getInstance() is the method of Java Currency class which is used to get an instance of currency for the given currency code. SyntaxFollowing is the declaration of getInstance(String currencyCode) method: Parameter
ReturnsThis method returns the instance of currency for the given currency code. ExceptionsNullPointerException - If currencyCode is null. IllegalArgumentException - If currencyCode is not a supported ISO 4216 code. Compatibility VersionJava 1.4 and above Example 1Output: Indian Rupee Example 2Output: Currency code of US: USD Currency name of US: US Dollar Example 3Output: Enter the Currency name: INR Currency is: Indian Rupee Example 4Output: ---------Indian Currency---------- Currency display name: Indian Rupee Currency Code: INR Currency Numeric Code: 356 |