Java.math.BigInteger Class Java.math.BigInteger.compareTo() Method - Java.math Package

What is Java math BigInteger compareTo() Method?


The java.math.BigInteger.compareTo(BigInteger val) compares this BigInteger with the required BigInteger. This technique is supplied in desire to individual techniques for every of the six boolean comparison operators (<, ==, >, >=, !=, <=).

The suggested idiom for performing these comparisons is: (x.compareTo(y) 0), where is one of the six comparison operators.


Following is the declaration for java.math.BigInteger.compareTo() technique.

Specified by

Compare To in interface Comparable<BigInteger>.


Val – Big Integer to which this BigInteger is to be compared.

Return Value

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




The following example suggests the usage of math.BigInteger.compareTo()technique.

Let us compile and run the above program, this will produce the following result −

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

Java.math Package Topics