Compare two boolean values
int compareTo(Boolean b)
- Compares this Boolean instance with another.
boolean equals(Object obj)
- Returns true if the argument is not null and is a Boolean object that represents the same boolean value as this object.
compareTo(Boolean b) returns:
Value | Meaning |
---|---|
zero | if this object represents the same boolean value as the argument; |
a positive value | if this object represents true and the argument represents false; |
a negative value | if this object represents false and the argument represents true |
public class Main {
public static void main(String[] args) {
Boolean boolean1 = new Boolean("true");
System.out.println(boolean1);
Boolean boolean2 = new Boolean(true);
System.out.println(boolean2.compareTo(boolean1));
}
}
The output:
true
0