java.math.MathContext.equals(Object x) 用MathContext與指定物件的相等性比較。
以下是java.math.MathContext.equals()方法的宣告
public boolean equals(Object x)
在類 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