Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java
boolean
xor
communitycreator

What is Boolean.logicalXor in java?

abhilash

Overview

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 values

A 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

Syntax

public static boolean logicalXor(boolean a, boolean b)

Parameters

  • boolean a - first operand.
  • boolean b - second operand.

Returns

Logical XOR of the two operands.

Code

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));
    }
}

RELATED TAGS

java
boolean
xor
communitycreator
RELATED COURSES

View all Courses

Keep Exploring