货币类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 Currency
import java.util.*;
public class GetInstanceOfCurrency {public static void main(String args[]) {// Instantiates a currency with INR code
Currency c1 = Currency.getInstance("INR");
// Instantiates a currency for the given locale
Locale lo = Locale.US;
Currency c2 = Currency.getInstance(lo);
// By using getInstance(c1) method is to return
// the Currency instance for the given currency code
System.out.print("c1.getCurrencyCode(): ");
System.out.println(c1.getCurrencyCode());
// By using getSymbol(lo) method is to return
// the Currency instance for the given locale
System.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()方法与示例相关推荐

  1. Java IOUtils.copy方法代码示例(亲测)

    本文整理汇总了Java中org.apache.commons.io.IOUtils.copy方法的典型用法代码示例.如果您正苦于以下问题:Java IOUtils.copy方法的具体用法?Java I ...

  2. java currency 默认_Java Currency getDefaultFractionDigits()方法与示例

    Currency类getDefaultFractionDigits()法getDefaultFractionDigits()方法在java.util包中可用. getDefaultFractionDi ...

  3. java currency 默认_Java Currency getCurrencyCode()方法与示例

    Currency类getCurrencyCode()法getCurrencyCode()方法在java.util包中可用. getCurrencyCode()方法用于获取此Currency的ISO 4 ...

  4. java currency 默认_Java Currency.equals方法代码示例

    import nl.strohalm.cyclos.entities.accounts.Currency; //导入方法依赖的package包/类 @Override public Validatio ...

  5. java user directory,Java ProcessBuilder directory()方法与示例

    语法:public File directory (); public ProcessBuilder directory (File dir); ProcessBuilder类directory()方 ...

  6. Java序列化魔术方法及其示例使用

    在上一篇文章中, 您需要了解有关Java序列化的所有知识 ,我们讨论了如何通过实现Java序列化来启用类的可序列化性. Serializable接口. 如果我们的类未实现Serializable接口, ...

  7. catalog java,Java Connection getCatalog()方法与示例

    通常,目录是一个目录,其中包含有关数据集,文件或数据库的信息.而数据库目录中包含所有数据库,基本表,视图(虚拟表),同义词,值范围,索引,用户和用户组的列表. Connection接口的getCata ...

  8. filepermission java,Java FilePermission getActions()方法与示例

    FilePermission类getActions()方法getActions()方法在java.io包中可用. getActions()方法用于检查此FilePermission和给定对象在路径名和 ...

  9. java方法参数Bundle,Java ResourceBundle keySet()方法及示例

    ResourceBundle类keySet()方法keySet()方法在java.util包中可用. keySet()方法用于从此ResourceBundle及其超级捆绑包中获取所有现有键,以在Set ...

最新文章

  1. kvm cpu的亲和性绑定配置
  2. ubuntu 12.04 添加 IP并配置DNS
  3. Gitlab+Gerrit+Jenkins完整对接
  4. OAF_开发系列21_实现OAF事物控制TransactionUnitHelper(案例)
  5. Codeforces 1276C/1277F/1259F Beautiful Rectangle (构造)
  6. Qt网络编程之实例一GET方式
  7. 使用Apache Cassandra设置SpringData项目
  8. 产品经验谈:一文讲清楚商业模式梳理怎么做?
  9. 【51Nod - 1133】不重叠的线段 (贪心)
  10. linux7配置dns服务器,centOS7搭建DNS服务器配置详解
  11. Objections vs. excuses
  12. clion导入mysql库_CLion如何添加依赖库 ? 需要把mysql/Connector c++放入 用cpp连接数据库...
  13. Unity3D之UGUI基础6:Slider滑条
  14. Angular2快速入门-1.创建第一个app
  15. 记录几种常用编码方式:BASE64、MD5
  16. 博客园博客转至个人网站博客声明
  17. Docker实现ElasticSearch集群搭建
  18. 关于速算:2^n,2的各个阶乘的记忆方法
  19. Java 将两个日期的时间段按照一定天数进行周期切割
  20. 好评度前五的扫地机器人

热门文章

  1. webpack 读取文件夹下的文件_webpack基本介绍及使用
  2. 网页搜索帮助-禁止搜索引擎收录的方法
  3. 修改gitlab数据卷的位置
  4. 教你如何把自己从好友的QQ中删除
  5. ELK系列~对fluentd参数的理解
  6. Silverlight 异步单元测试
  7. HDS:聚焦未来的投资“冻结”
  8. Python模拟删除字符串两边的空白
  9. 如何下载防盗链的歌曲?
  10. (转)解读NTFS(一)