java.math.MathContext.equals(Object x) 用MathContext与指定对象的相等性比较。
声明
以下是java.math.MathContext.equals()方法的声明
public boolean equals(Object x)
Overrides
在类 Object 中的equals
参数
-
x - 其中此MathContext 要比较的对象
返回值
当且仅当指定的Object是一个MathContext对象具有完全相同的设置与此对象此方法返回true。
异常
-
NA
例子
下面的例子显示math.MathContext.equals()方法的用法
package com.yiibai; 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