Java-math-biginteger-equals

提供:Dev Guides
移動先:案内検索

Java.math.BigInteger.equals()メソッド

説明

  • java.math.BigInteger.equals(Object x)*は、このBigIntegerが指定されたオブジェクトと等しいかどうかを比較します。

宣言

以下は* java.math.BigInteger.equals()*メソッドの宣言です。

public boolean equals(Object x)

オーバーライド

クラス Object で等しい。

パラメーター

*x* -このBigIntegerが比較されるオブジェクト。

戻り値

このメソッドは、指定されたObjectが、このBigIntegerと数値的に等しいBigIntegerである場合にのみtrueを返します。

例外

NA

次の例は、math.BigInteger.equals()メソッドの使用法を示しています。

package com.finddevguides;

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