Conditional and logical operators and expressions
The conditional operators are shown in Table 1.
The logical operators are shown in Table 2.
If you are entering && in an HTML or XML editor you
might have to enter &&
Operator | Operation |
---|---|
== | Equal |
!= | Not equal |
> | Greater than |
< | Less than |
>= | Greater than or equal |
<= | Less than or equal |
Operator | Operation |
---|---|
&& | AND |
|| | OR |
! | NOT |
In a conditional expression the terms are evaluated
left to right. The order of precedence of the operators is the same
order in which they are listed in the tables above. You can use parentheses
to indicate the order in which you want expressions to be evaluated.
Examples:
Expression: Evaluates to:
(4 > 3) true
!(4 > 3 ) false
(4 > 3) && (8 > 10) false
(4 > 3) || (8 > 10) true
A conditional expression can contain arithmetic expressions, variables, and calls to methods of imported Java™ classes.
Conditional and logical operators can be used in only two contexts:
- The Condition field of a conditional descriptor
- The Condition field of a conditional action