compareTo

operator fun compareTo(other: Integer): Int

Compares this integer with the other one for order.

Returns a negative number, zero, or a positive number as this integer is less than, equal to, or greater than the other one.


Calling from Kotlin

Here's an example of calling this function from Kotlin code:

val x: Integer = Integer.parse("-99999999999999999999")
val y: Integer = Integer.parse("99999999999999999999")
val result: Boolean = x < y // or x.compareTo(y) < 0
check(result)

Calling from Java

Here's an example of calling this function from Java code:

final Integer x = Integer.parse("-99999999999999999999");
final Integer y = Integer.parse("99999999999999999999");
final boolean result = x.compareTo(y) < 0;
if (!result) throw new IllegalStateException("Check failed.");