Facebook Page Twitter Page LinkedIn Page
× Java.lang Package Classes


The java.lang.Boolean.logicalXor() method is used to return the result of applying the logical XOR operator to the specified boolean operands.

Syntax

public static boolean logicalXor(boolean a,
                                 boolean b)

Parameters

a Specify the first operand.
b Specify the second operand.

Return Value

Returns the logical XOR of a and b.

Exception

NA.

Example:

In the below example, the java.lang.Boolean.logicalXor() method is used to return the result of applying the logical XOR operator to the given boolean operands.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //creating boolean values
    boolean b1 = true;
    boolean b2 = false;

    //printing the result of applying XOR operator  
    System.out.println("b1 XOR b1: " + Boolean.logicalXor(b1, b1)); 
    System.out.println("b2 XOR b2: " + Boolean.logicalXor(b2, b2));  
    System.out.println("b1 XOR b2: " + Boolean.logicalXor(b1, b2));   
  }
}

The output of the above code will be:

b1 XOR b1: false
b2 XOR b2: false
b1 XOR b2: true

❮ Java.lang - Boolean