Java basic operators: relational operators and logical operators

Relational operators and usage

Operator How to use Explanation
> op1 > op2 If op1 is greater than op2
>= op1 >= op2 If op1 is greater than or equal to op2
< op1 < op2 If op1 is smaller than op2
< op1 <= op2 If op1 is less than or equal to op2
== op1 == op2 If op1 and op2 are the same
!= op1 != op2 If op1 and op2 are not equal
instanceof op1 instanceof op2 If op1 is an instance(object) of op2

Logical Operators and Usage

Operator How to use Explanation
& op1 & op2 true if op1 and op2 are both true, evaluate both op1 and op2
&& op1 && op2 true if op1 and op2 are both true, op2 is not evaluated if op1 is true
| op1 | op2 true if at least one of op1 and op2 is true, evaluating both op1 and op2
|| op1 || op2 true if at least one of op1 and op2 is true; op2 is not evaluated if op1 is true.
! !op false if op is true, true if false

Share This Post

댓글 남기기

이메일은 공개되지 않습니다. 필수 입력창은 * 로 표시되어 있습니다

Latest Post