Java BigInteger compareTo() method

The compareTo() method of Java BigIntegerclass is used to compare two BigIntegervalues.This method is provided in preference to individual methods for each of the six boolean comparison operators (<, == ,> ,>=, !=, <=). This method computes (x.compareTo(y) <op> 0) , where <op> is one of the six comparison operators.

Syntax:

Parameter:

val-BigInteger to which this BigInteger is to be compared

Returns:

This method returns -1, 0 or 1 as this BigInteger is numerically less than, equal to, or greater than val.

Note: This method is specified by compareTo in interfaceComparable <BigInteger>.

Example

Test it Now

Output:

First value is greater.

Next TopicJava BigInteger




Latest Courses