Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

^ operator in java [duplicate]

Tags:

java

operators

Can anyone explain the use of ^ operator in java with some examples?

like image 541
Warrior Avatar asked Jan 20 '09 09:01

Warrior


People also ask

What is clone () in Java?

The Java Object clone() method creates a shallow copy of the object. Here, the shallow copy means it creates a new object and copies all the fields and methods associated with the object. The syntax of the clone() method is: object.clone()

What is the += operator in Java?

The addition assignment operator ( += ) adds the value of the right operand to a variable and assigns the result to the variable.

Can you use || in Java?

The || operator can only be used, in Java, where a boolean (true or false) expression is expected, such as in an if statement like the above. So pretty much in an if or a conditional operator (that ?...: thing, sometimes called the ternary operator).

What do && mean in Java?

The symbol && denotes the AND operator. It evaluates two statements/conditions and returns true only when both statements/conditions are true.


2 Answers

This is the same as ^ in most languages, just an XOR.

false ^ false == false true ^ false == true false ^ true == true true ^ true == false  
like image 108
Serafina Brocious Avatar answered Sep 18 '22 05:09

Serafina Brocious


Some of the other answers only say it is a bitwise XOR, but note that it can also be a logical XOR if the operands are of boolean type, according to this source.

like image 23
Museful Avatar answered Sep 21 '22 05:09

Museful