Java NumberFormat clone()方法及示例

来源:这里教程网 时间:2026-02-17 20:59:28 作者:

Java NumberFormat clone()方法及示例

clone() 方法是 java.text.NumberFormat 的一个内置方法,它返回一个定义了任何给定实例的克隆的对象。

语法:

public Object clone()

参数 :该函数不接受任何参数。

返回值 :该函数返回一个对象,该对象定义了任何给定实例的克隆。

下面是上述函数的实现。

程序 1 :

// Java program to implement// the above functionimport java.text.NumberFormat;  public class Main {    public static void main(String[] args)        throws Exception    {          // Get the percent Instance        NumberFormat nF            = NumberFormat                  .getPercentInstance();          // Print the clone of this instance        System.out.println(nF.clone());    }}

输出。

java.text.DecimalFormat@674dc

程序2

// Java program to implement// the above function  import java.text.NumberFormat;  public class Main {    public static void main(String[] args)        throws Exception    {          // Get the Currency Instance        NumberFormat nF            = NumberFormat                  .getCurrencyInstance();          // Print the clone of this instance        System.out.println(nF.clone());    }}

输出。

java.text.DecimalFormat@67500

**参考资料: ** https://docs.oracle.com/javase/10/docs/api/java/text/NumberFormat.html#clone()

相关推荐