Java.math.BigInteger.equals() 方法



描述

java.math.BigInteger.equals(Object x) 將此 BigInteger 與指定的 Object 進行比較以判斷相等性。

宣告

以下是 java.math.BigInteger.equals() 方法的宣告。

public boolean equals(Object x)

覆蓋

Object 類中的 equals。

引數

x − 將此 BigInteger 與之比較的物件。

返回值

僅當指定 Object 為其值在數值上等於此 BigInteger 的 BigInteger 時,此方法才返回 true。

異常

不適用

示例

以下示例演示了 math.BigInteger.equals() 方法的用法。

package com.tutorialspoint;

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
java_math_biginteger.htm
廣告
© . All rights reserved.