Boolean compare() method in Java with Examples Last Updated : 08 Oct, 2018 Comments Improve Suggest changes Like Article Like Report 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. Syntax: 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: Program 1: JAVA // Java code to implement // compare() method of Boolean class class GeeksforGeeks { // Driver method public static void main(String[] args) { // first value boolean a = true; // second value boolean b = true; // compare method System.out.println(a + " comparing with " + b + " = " + Boolean.compare(a, b)); } } Output: true comparing with true = 0 Program 2: JAVA // Java code to implement // compare() method of Java class class GeeksforGeeks { // Driver method public static void main(String[] args) { // first value boolean a = true; // second value boolean b = false; // compare method System.out.println(a + " comparing with " + b + " = " + Boolean.compare(a, b)); } } Output: true comparing with false = 1 Program 3: JAVA // Java code to implement // compare() method of Java class class GeeksforGeeks { // Driver method public static void main(String[] args) { // first value boolean a = false; // second value boolean b = true; // compare method System.out.println(a + " comparing with " + b + " = " + Boolean.compare(a, b)); } } Output: false comparing with true = -1 Comment More infoAdvertise with us Next Article Boolean compare() method in Java with Examples K kundankumarjha Follow Improve Article Tags : Java Java - util package Java-Functions Java-Byte Practice Tags : Java Similar Reads Boolean compareTo() method in Java with examples The compareTo() method of Boolean class is a built in method in Java which is used to compare the given Boolean instance with the current instance. Syntax: BooleanObject.compareTo(Boolean a) Parameters: It takes a Boolean value a as parameter which is to be compared with the current instance. Return 2 min read Byte compare() method in Java with examples The compare() method of Byte class is a built in method in Java which is used to compare two byte values. Syntax Byte.compare(byte a, byte b) Parameters: It takes two byte value 'a' and 'b' as input in the parameters which are to be compared. Return Value: It returns an int value. It returns: 0 if ' 2 min read Java Guava | Booleans.compare() method with Examples The compare() method of Booleans Class in the Guava library is used to compare the two specified boolean values. These values are passed as the parameter and the result of comparison is found as the difference of 1st value and the 2nd value. Hence it can be positive, zero or negative. Syntax: public 2 min read Byte compareTo() method in Java with examples The compareTo() method of Byte class is a built in method in Java which is used to compare the given Byte type object with the instance of Byte invoking the compareTo() method. Syntax ByteObject.compareTo(Byte a) Parameters: It takes a Byte type object a as input which is to be compared with the ins 2 min read Boolean equals() method in Java with examples The equals() method of Boolean class is a built in method of Java which is used check equality of two Boolean object. Syntax: BooleanObject.equals(Object ob) Parameter: It take a parameter ob of type Object as input which is the instance to be compared. Return Type: The return type is boolean. It re 2 min read Java File Class compareTo() Method with Examples The compareTo() function compares two pathnames lexicographically. In Java, the method may be used to sort files. This type of activity is dependent on the system on which JVM is installed. When comparing pathnames on Unix systems, the alphabetic case matters, while it doesn't on Windows. Syntax: pu 1 min read Float compare() Method in Java with Examples The compare() method of Float Class is a built-in method in Java that compares the two specified float values. The sign of the integer value returned is the same as that of the integer that would be returned by the function call. Syntax: public static int compare(float f1, float f2)Parameters: The f 2 min read Charset compareTo() method in Java with Examples The compareTo() method is a built-in method of the java.nio.charset compares two charsets with each other. A comparison is done by their canonical names, without regard to case. Syntax: public final int compareTo?(Charset second) Parameters: The function accepts a single mandatory parameter second w 1 min read Java Arrays compare() Method with Examples The Arrays compare() method in Java is a part of the java.util package to compare arrays lexicographically (dictionary order). This method is useful for ordering arrays and different overloads for different types including boolean, byte, char, double, float, int, long, short, and Object arrays. Exam 3 min read Like