Java Currency getInstance()方法与示例
貨幣類getInstance()方法 (Currency Class getInstance() method)
Syntax:
句法:
public static Currency getInstance(Locale lo);public static Currency getInstance(String curr_code);- getInstance() method is available in java.util package. - getInstance()方法在java.util包中可用。 
- getInstance(Locale lo) method is used to get the Currency instance for the specified Locale (lo). - getInstance(Locale lo)方法用于獲取指定的Locale(lo)的Currency實例。 
- getInstance(String curr_code) method is used to get the Currency instance for the specified Currency code (curr_code). - getInstance(String curr_code)方法用于獲取指定貨幣代碼(curr_code)的Currency實例。 
- These methods may throw an exception at the time of returning Currency instance. - 這些方法在返回Currency實例時可能會引發異常。 - NullPointerException: This exception may throw when the given parameter is null exists.NullPointerException :當給定參數為null時,可能引發此異常。
- IllegalArgumentException: This exception may throw when ISO 3166 un-support the given parameter.IllegalArgumentException :當ISO 3166不支持給定參數時,可能引發此異常。
 
- These are static methods, it is accessible with the class name and if we try to access these methods with the class object then also we will not get an error. - 這些是靜態方法,可以使用類名進行訪問,如果嘗試使用類對象訪問這些方法,則也不會出錯。 
Parameter(s):
參數:
- In the first case, getInstance(Locale lo), - 第一種情況是getInstance(Locale lo) , - Locale lo – represents the locale for whose Currency instance is needed.
- 語言環境lo –表示需要其Currency實例的語言環境。
 
- In the second case, getInstance(String curr_code) - 在第二種情況下, getInstance(String curr_code) - String curr_code – represent the currency code (curr_code).
- 字符串curr_code –代表貨幣代碼(curr_code)。
 
Return value:
返回值:
In both the cases, the return type of the method is Currency,
在這兩種情況下,方法的返回類型均為Currency 。
- getInstance(Locale lo) – returns Currency instance for the given locale (lo). - getInstance(Locale lo) –返回給定語言環境(lo)的Currency實例。 
- getInstance(String curr_code) – returns Currency instance for the given currency code (curr_code). - getInstance(String curr_code) –返回給定貨幣代碼(curr_code)的Currency實例。 
Example:
例:
// Java program is to demonstrate the example of // getInstance() method of Currencyimport java.util.*;public class GetInstanceOfCurrency {public static void main(String args[]) {// Instantiates a currency with INR codeCurrency c1 = Currency.getInstance("INR");// Instantiates a currency for the given localeLocale lo = Locale.US;Currency c2 = Currency.getInstance(lo);// By using getInstance(c1) method is to return// the Currency instance for the given currency codeSystem.out.print("c1.getCurrencyCode(): ");System.out.println(c1.getCurrencyCode());// By using getSymbol(lo) method is to return// the Currency instance for the given localeSystem.out.print("c2.getCurrencyCode(): ");System.out.println(c2.getCurrencyCode());} }Output
輸出量
c1.getCurrencyCode(): INR c2.getCurrencyCode(): USD翻譯自: https://www.includehelp.com/java/currency-getinstance-method-with-example.aspx
總結
以上是生活随笔為你收集整理的Java Currency getInstance()方法与示例的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: matlab在绘图时分数,第三章_Mat
- 下一篇: lambda python_Python
