Boolean compare() method in Java with Examples
The compare() method of Boolean class is a built in method in Java which is used to compare two boolean values. It is a static method, so it can be called without creating any object of the Boolean class i.e. directly using the class name.
Boolean.compare(boolean a, boolean b)
Parameters: It takes two boolean values a and b in the parameter which are to be compared.
Return Type: The return type of the function is int. It returns
- 0 if ‘a’ is equal to ‘b’,
- a negative value if ‘a’is false and ‘b’ is true,
- a positive value if ‘a’ is true and ‘b’ is false.
Below are programs to illustrate the compare() method of Boolean class:
true comparing with true = 0
true comparing with false = 1
false comparing with true = -1
My Personal Notes arrow_drop_up
Please Login to comment...