Compare two boolean values

ReturnMethodSummary
intcompareTo(Boolean b)Compares this Boolean instance with another.
booleanequals(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:

ReturnMeaning
zeroif this object represents the same boolean value as the argument;
a positive valueif this object represents true and the argument represents false;
a negative valueif 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
java2s.com  |  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.