The compareTo() method of Java Boolean class compares the Boolean argument with the Boolean instance and returns integer value, zero, or negative 1, or positive 1 based on the result of this method.

 Syntax

public int compareTo(Boolean b)

Parameters

The parameter ‘b’ represents the Boolean instance which is compared.

Return Value

This method returns an integer value based on the result.

  • It returns zero, if the parameter b is equal to Boolean instance.
  • It returns positive 1, if object b represents true and the argument represents false.
  • It returns a negative 1, if object b represent false and the argument represent true.

Example 1

Output

Example 2

Output

Example 3

Output

Pin It on Pinterest

Share This