The compare()  method of Integer class compares the two specified int values.


public static int compare(int x, int y)


The parameters ‘x’ and ‘y’ represent the first and second int values to be compared.

 Return Value

This method returns an integer value.

  • It returns zero, if both the parameters are equal(x==y).
  • It returns positive one, if x is greater than y(x>y).
  • It returns negative one, if x if smaller than y(x<y).

Example 1


Example 2


Example 3


Pin It on Pinterest

Share This