The compare() method of Java Boolean class compares the specified Boolean values and returns a positive 1 or negative 1 or zero integer value based on the result.


public static int compare(boolean  x, boolean y)


The ‘x’ and ‘y’ represents the first and second Boolean parameters which are compared.

Return Value

This method returns an integer value which is as follows:

  • It returns an integer value zero, if x and y are equal.
  • It returns a positive integer value 1, if x is true and y is false.
  • It returns a negative integer value -1, if x is false and y is true.

Example 1:


Example 2:


Example 3:


Pin It on Pinterest

Share This