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實(shí)例。
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實(shí)例。
These methods may throw an exception at the time of returning Currency instance.
這些方法在返回Currency實(shí)例時(shí)可能會(huì)引發(fā)異常。
- NullPointerException: This exception may throw when the given parameter is null exists.NullPointerException :當(dāng)給定參數(shù)為null時(shí),可能引發(fā)此異常。
- IllegalArgumentException: This exception may throw when ISO 3166 un-support the given parameter.IllegalArgumentException :當(dāng)ISO 3166不支持給定參數(shù)時(shí),可能引發(fā)此異常。
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.
這些是靜態(tài)方法,可以使用類名進(jìn)行訪問(wèn),如果嘗試使用類對(duì)象訪問(wèn)這些方法,則也不會(huì)出錯(cuò)。
Parameter(s):
參數(shù):
In the first case, getInstance(Locale lo),
第一種情況是getInstance(Locale lo) ,
- Locale lo – represents the locale for whose Currency instance is needed.
- 語(yǔ)言環(huán)境lo –表示需要其Currency實(shí)例的語(yǔ)言環(huán)境。
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) –返回給定語(yǔ)言環(huán)境(lo)的Currency實(shí)例。
getInstance(String curr_code) – returns Currency instance for the given currency code (curr_code).
getInstance(String curr_code) –返回給定貨幣代碼(curr_code)的Currency實(shí)例。
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
總結(jié)
以上是生活随笔為你收集整理的Java Currency getInstance()方法与示例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: matlab在绘图时分数,第三章_Mat
- 下一篇: strictmath_Java Stri