Java - Logical XOR Operator ^

What is Logical XOR Operator?

The logical XOR operator (^) is used in the form

operand1 ^ operand2 

The logical XOR operator returns true if operand1 and operand2 are different. It returns true if one of the operands is true, but not both. If both operands are the same, it returns false.

int i = 10; 
boolean b; 
  
b = true ^ true;      // Assigns false to b 
b = true ^ false;     // Assigns true to b 
b = false ^ true;     // Assigns true to b 
b = false ^ false;    // Assigns false to b 
b = (i > 5 ^ i < 15); // Assigns false to b 

Demo

public class Main {
  public static void main(String[] args) {
    int i = 10; //  w ww  .  j a v a 2 s .c  o m
    boolean b; 
      
    b = true ^ true;      // Assigns false to b
    System.out.println ("b = " + b); 
    b = true ^ false;     // Assigns true to b
    System.out.println ("b = " + b); 
    b = false ^ true;     // Assigns true to b
    System.out.println ("b = " + b); 
    b = false ^ false;    // Assigns false to b
    System.out.println ("b = " + b); 
    b = (i > 5 ^ i < 15); // Assigns false to b 
    System.out.println ("b = " + b); 

  }
}

Result