EX-OR Boolean Operator in Java

chris rued cbr at michaelpee.homeip.net
Fri May 21 10:54:32 PDT 2004


Thorsten Greiner wrote:

>* Christopher Rued <c.rued at xsb.com> [2004-05-21 18:31]:
>> (a && !b) || (!a && b).
>> There is no XOR boolean operator in Java, AFAIK.
>
>Come on guys, think before you hit that send button: the boolean
>operators in Java are:
>
>    !   NOT
>    &   AND
>    |   OR
>    ^   XOR
>
>There are two short-ciruit operators:
>
>    &&  AND
>    ||  OR
>
>These do not evaluate their right hand side expression if the left
>side is either false (&&) or true (||). You actually should find
>
>that in any entry level book on Java programming.
>
I stand corrected.

As Thorsten ever so politely pointed out, a ^ b works just fine, and is 
logically equivalent to my original suggestion.

I knew of & and | as the non-short-circuit versions of && and ||, but I 
didn't know that ^ was a valid operator on booleans.
I only knew of ^ as a bit-wise operator on numerical primitives before.

--Chris




More information about the freebsd-java mailing list