Java Reference
In-Depth Information
Table 4-5.
(
continued
)
Operator
Name
Syntax
Description
||
op1 || op2
Returns
op1
or
op2
. If
op1
is
true
or can
be converted to
true
,
op1
is returned.
Otherwise,
op2
is returned.
Logical OR
?:
op1 ? op2 :
op3
If
op1
evaluates to true, returns the value
of op2. Otherwise, returns the value of
op3.
Conditional
or ternary
operator
=
op1 = op2
Assigns the value of
op2
to
op1
and
returns
op2
.
Assignment
+=, -=,
*=, /=,
%=, <<=,
>>=, >>>=,
&=, ^=, |=
op1 op= op2
Works as if a statement like
op1 = op1 op
op2
is executed. Applies the operation
(+, =, *, /, %, etc.) on
op1
and
op2
, assigns
the result to op1 and returns the result.
Compound
assignment
,
op1, op2,
op3...
Comma
operator
Evaluates each of its operands from left
to right and returns the value of the last
operand. Used in locations where one
expression is required, but you want to
use multiple expressions, for example, in
a
for
loop header.
Operators have precedence. In an expression, operators with the higher precedence
are evaluated before operators with the lower precedence. Like Java, you can enclose part
of an expression in parentheses that has the highest precedence. The following is the list
of precedence of operators. Operators at level 1 have higher precedence than those at
level 2. Operators at the same level have the same precedence:
1.
++
(Postfix increment),
--
(postfix decrement)
2.
!, ~, +
(Unary plus),
-
(Unary negation),
++
(Prefix
increment),
--
(Prefix decrement),
typeof
,
void
,
delete
3.
*, /, %
4.
+
(Addition),
-
(Subtraction)
5.
<< , >>, >>>
6.
<, <=, >, >=, in, instanceof
7.
==, !=, ===, !==
8.
&
9.
^
10.
|
Search WWH ::
Custom Search