Java.math.MathContext.equals() 方法
描述
java.math.MathContext.equals(Object x) 将此 MathContext 与指定的 Object 进行比较是否相等。
声明
以下是 java.math.MathContext.equals() 方法的声明。
public boolean equals(Object x)
Overrides
equals in class Object.
参数
x − 此 MathContext 要与之比较的对象。
返回值
当且仅当指定的 Object 是与此对象具有完全相同设置的 MathContext 对象时,此方法才返回 true。
异常
NA
示例
下面的例子展示了 math.MathContext.equals() 方法的使用。
package com.tutorialspoint;
import java.math.*;
public class MathContextDemo {
public static void main(String[] args) {
// create 3 MathContext objects
MathContext mc1, mc2, mc3;
// assign context settings to mc1, mc2, mc3
mc1 = new MathContext(2);
mc2 = new MathContext(2, RoundingMode.HALF_UP);
mc3 = new MathContext(2, RoundingMode.HALF_DOWN);
// create 2 boolean objects
Boolean b1, b2;
// compare context settings of mc1 with mc2, mc3
b1 = mc1.equals(mc2);
b2 = mc1.equals(mc3);
String str1 = "Context settings of mc1 and mc2 are equal is " + b1;
String str2 = "Context settings of mc1 and mc3 are equal is " + b2;
// print b1, b2 values
System.out.println( str1 );
System.out.println( str2 );
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
Context settings of mc1 and mc2 are equal is true Context settings of mc1 and mc3 are equal is false

