In java, there is a logical OR operator (||
) and a logical AND operator (&&
). Is there a logical XOR operator? I tried ^^
but it does not work.
The logical XOR operator does exist in Java and is spelled ^
.
To get the terminology right, in Java:
&
, |
and ^
are called bitwise or logical operators, depending on the types of their arguments;&&
and ||
are called conditional operators.For details, see JLS § 15.22. Bitwise and Logical Operators onwards.
There is no direct equivalent for &&
and ||
for XOR. The only reason &&
and ||
exist as separate operators from &
and |
is their short-circuiting behaviour (that's why they're called "conditional"), and XOR cannot be short-circuited.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With