The java.math.BigInteger.equals(Object x) method compares this BigInteger with the object passed as the parameter and returns true in both are equal in value else it returns false.
public boolean equals(Object x)
Parameter: This method accepts a single mandatory parameter x which is the Object to which BigInteger Object is to be compared.
Returns: This method returns boolean true if and only if the Object passed as parameter is a BigInteger whose value is equal to the BigInteger Object on which the method is applied. Otherwise it will return false.
Input: BigInteger1=2345, BigInteger2=7456 Output: false Explanation: BigInteger1.equals(BigInteger2)=false. Input: BigInteger1=7356, BigInteger2=7456 Output: true Explanation: BigInteger1.equals(BigInteger2)=true.
Below programs illustrate equals() method of BigInteger class:
Example 1: When both are equal in value.
BigInteger1 321456 and BigInteger2 321456 are equal
Example 2: When both are not equal in value.
BigInteger1 321456 and BigInteger2 456782 are not equal
Example 3: When object passed as parameter is other than BigInteger.
BigInteger1 321456 and String Object 321456 are not equal
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.