What is the xor boolean operator in java?

In java, there is a logical operator OR ( || ) and a logical operator AND ( && ). Is there a logical XOR operator ? I tried ^^ but it does not work.

+6
source share
1 answer

The logical XOR operator exists in Java and is written ^ .

To get the terminology correct, in Java:

  • & , | and ^ are called bitwise or logical operators, depending on the types of their arguments;
  • && and || are called conditional statements.

See JLS Β§ 15.22 for details. Bitwise and logical operators .

There is no direct equivalent for && and || for xor . The only reason && and || exists as separate operators from & , and | - their short circuit behavior (which is why they are called "conditional"), and XOR cannot be shorted.

+18
source

Source: https://habr.com/ru/post/976801/


All Articles