当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java NumberFormat clone()用法及代码示例


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

用法

public Object clone()

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


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

下面是上述函数的实现:

示例1:

// Java program to implement 
// the above function 
import 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()



相关用法


注:本文由纯净天空筛选整理自gopaldave大神的英文原创作品 NumberFormat clone() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。