Skip to content

Latest commit

 

History

History
33 lines (26 loc) · 996 Bytes

File metadata and controls

33 lines (26 loc) · 996 Bytes

15. Operators ( Boolean Logical Operators )

Operator Operation
& Logical AND
^ Logical XOR
&& Short-circuit AND
! Logical Unary NOT
&= AND assignment
=
^= XOR assignment
== Equal to
! = Not Equal to
?: Ternary if-then-else

Boolean logical operators shown above operate only on boolean operands.

Short-circuit logical operators will not evaluate the right hand operand if the outcome of the expression can be determined from the left operand alone.

A && B; results in false when A is false no matter what B is and A || B results in true when A is true no matter what B is.

💡 It is also very helpful when right hand operand depends on the value of left one.
String x = null;
if(x!=null && x.length()>1){}; // doesnot compute right operand
if(x!=null & x.length()>1){}; // computes both operand and throws error