java.math.BigInteger.equals(Object x) 比較此BigInteger與指定物件是否相等。
以下是java.math.BigInteger.equals()方法的宣告
public boolean equals(Object x)
equals在類Object中
x - 與BigInteger比較的物件
當且僅當指定的物件Object是一個BigInteger,其值在數值上等於此BigInteger此方法返回true。
NA
下面的例子顯示math.BigInteger.equals()方法的用法
package com.yiibai; import java.math.*; public class BigIntegerDemo { public static void main(String[] args) { // create 2 BigInteger objects BigInteger bi1, bi2; bi1 = new BigInteger("123"); bi2 = new BigInteger("123"); // create 2 boolean objects Boolean b1, b2; // compare bi1 with bi2 b1 = bi1.equals(bi2); // compare bi1 with an object value 123, which is not a BigIntger b2 = bi1.equals("123"); String str1 = bi1 + " equals BigInteger " + bi2 + " is " +b1; String str2 = bi1 + " equals object value 123 is " +b2; // print b1, b2 values System.out.println( str1 ); System.out.println( str2 ); } }
讓我們編譯和執行上面的程式,這將產生以下結果:
123 equals BigInteger 123 is true 123 equals object value 123 is false