Does Java have an &=
operator? I'm seeing this code:
boolean allReady = true;
for(Entry<String,Boolean> ace : factory.readyAces.entrySet()) {
allReady &= ace.getValue();
What is &=
?
The & operator in Java has two definite functions: As a Relational Operator: & is used as a relational operator to check a conditional statement just like && operator. Both even give the same result, i.e. true if all conditions are true, false if any one condition is false.
Java has two operators for performing logical And operations: & and &&. Both combine two Boolean expressions and return true only if both expressions are true.
& is a bitwise operator and compares each operand bitwise. It is a binary AND Operator and copies a bit to the result if it exists in both operands. (A & B) will give 12 which is 0000 1100. Whereas && is a logical AND operator and operates on boolean operands.
The symbol && denotes the AND operator. It evaluates two statements/conditions and returns true only when both statements/conditions are true.
It's the same as:
allReady = allReady & ace.getValue();
This is a bit-wise and. It means you always evaluate both sides, then take the "logical and" (result is only true if both sides are true).
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