The logicalXor method is a static method of the Boolean class in Java.
The method computes the logical XOR operation on two Boolean operands/values. The logical XOR operator is represented as ^ in Java.
This method was introduced in Java 8.
XOR operation on Boolean valuesA boolean data type can take 2 values i.e., true and false. The logical XOR operation between the different combinations of the 2 boolean data types is as follows.
| First Operand | Second Operand | First Operand ^ Second Operand | 
|---|---|---|
| true | true | false | 
| true | false | true | 
| false | true | true | 
| false | false | false | 
public static boolean logicalXor(boolean a, boolean b)
boolean a - first operand.boolean b - second operand.Logical XOR of the two operands.
public class Main {public static void main(String[] args) {System.out.println("true ^ true = " + Boolean.logicalXor(true, true));System.out.println("true ^ false = " + Boolean.logicalXor(true, false));System.out.println("false ^ true = " + Boolean.logicalXor(false, true));System.out.println("false ^ false = " + Boolean.logicalXor(false, false));}}