Differences between & and && operators in Java.


& 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.

Assume integer variable A holds 60 and variable B holds 13 then  

(A & B) will give 12 which is 0000 1100.

Whereas && is a logical AND operator and operates on boolean operands. If both the operands are true, then the condition becomes true otherwise it is false. Assume boolean variable A holds true and variable B holds false then (A && B) is false.

& is to be used during bitwise operations and && is useful during logical operations.



Updated on: 30-Jul-2019

7K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements