File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes difference between !=(Not equal) and ^(XOR) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "difference between !=(Not equal) and ^(XOR)" Watch "difference between !=(Not equal) and ^(XOR)" New topic

difference between !=(Not equal) and ^(XOR)

Jonah Hague

Joined: Apr 28, 2008
Posts: 1
Is there another difference between an inequality test on booleans and an Exclusive OR besides the obvious fact that a XOR is only for booleans and a NOT EQUAL is also for ints, floats,...

both of these if-statements seem to accomplish the same thing
Nickolas Case
Ranch Hand

Joined: Apr 26, 2008
Posts: 98
XOR allows you to test against more than one argument and evaluates to true if and only if one of the arguments you are checking against is true.
For example:

Whereas != is only one argument at a time

Hope this helps.
[ April 28, 2008: Message edited by: Nickolas Case ]
Dan Walin
Ranch Hand

Joined: Nov 11, 2003
Posts: 109
just for accuracy, in your sample code shouldn't it be:

Using the equals "==" rather than the assignment "=" operator?
Nickolas Case
Ranch Hand

Joined: Apr 26, 2008
Posts: 98
Yes it should. Adjusted accordingly. :-)
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112

if(true == false^true)

is exactly the same as


which is equivalent to


which again is exactly the same as

if(true == (false!=true))

So I really don't understand the distinction you are making.

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
I agree. Here's the link:
subject: difference between !=(Not equal) and ^(XOR)
jQuery in Action, 3rd edition