Learn Java Programming – Logical Operator ^ (xor)



Learn Java Programming – Logical Operator ^ (xor)

Learn Java Programming - Logical Operator ^ (xor)

In Java, the ^ (XOR) logical operator compares two or more conditional expressions and returns true if exactly one of the conditional expressions evaluates to true. The ^ is also a bitwise operator, but this tutorial will not cover that functionality. I rarely use this operator, but there was this circumstance a long time ago where I was using it and a funny thing popped into my head. The way this operator functions reminded me of the old Duck-Duck-Goose game I played as a kid. I know – it’s really corny, but there can be only one Goose and any number of Ducks. When the Goose is named, the kids start to run. Just like that silly game, there can be only one True evaluation and any number of False evaluations. As long as exactly one conditional expression evaluates to True, the code block will run.

Comments are closed.