Java DecimalFormat equals()方法
equals()方法是 java.text.DecimalFormat 类的一个内置方法,它接受一个对象参数,如果该参数对象与该对象相同,则返回真,否则返回假。
语法:
public boolean equals(Object arg)
参数 :该函数接受一个强制参数arg,它指定了要比较的对象。
返回值 :该函数返回一个布尔值。如果两个对象相同,则返回真,否则返回假。
下面是上述函数的实现。
程序1 :
// Java program to illustrate the// equals() method import java.text.DecimalFormat;import java.util.Currency;import java.util.Locale; public class Main { public static void main(String[] args) { // Get the Currency Instance DecimalFormat dF1 = new DecimalFormat(); dF1.getCurrencyInstance(); // Get the Currency Instance DecimalFormat dF2 = new DecimalFormat(); dF2.getCurrencyInstance(); // Check if equal or not if (dF1.equals(dF2)) System.out.println("Yes both are equal"); else System.out.println("Yes both are not equal"); }}
输出:
Yes both are equal
程序2 :
// Java program to illustrate the// equals() method import java.text.DecimalFormat;import java.util.Currency;import java.util.Locale; public class Main { public static void main(String[] args) { // Get the Currency Instance DecimalFormat dF1 = new DecimalFormat(); dF1.getCurrencyInstance(); // Get Instance DecimalFormat dF2 = new DecimalFormat(); dF2.setCurrency(Currency.getInstance(Locale.GERMANY)); // Check if equal or not if (dF1.equals(dF2)) System.out.println("Yes both are equal"); else System.out.println("Yes both are not equal"); }}输出:
Yes both are not equal
参考资料 : https://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html#clone()
