2.6. Operators
Operators perform operations on one, two, or three operands and return a result. Operator types in Java include assignment, arithmetic, comparison, bitwise, increment/decrement, and class/object. Table 2-4 contains the Java operators listed in precedence order (those with the highest precedence at the top of the table), along with a brief description of the operators and their associativity (left to right or right to left).
Precedence | Operator | Description | Association |
---|---|---|---|
1 | ++,-- | Postincrement, Postdecrement | R L |
2 | ++,-- | Preincrement, Predecrement | R L |
+,- | Unary plus, unary minus | R L | |
~ | Bitwise compliment | R L | |
! | Boolean NOT | R L | |
3 | new | Create object | R L |
(type) | Type cast | R L | |
4 | *,/,% | Multiplication, division, remainder | L R |
5 | +,- | Addition, subtraction | L R |
+ | String concatenation | L R | |
6 | <<, >>, >>> | Left shift, right shift, unsigned right shift | L R |
7 | <, <=, >, >= | Less than, less than or equal to, greater than, greater than or equal to | L R |
instanceof | Type comparison | L R | |
8 | ==, != | Value equality and inequality | L R |
==, != | Reference equality and inequality | L R | |
9 | & | Boolean AND | L R |
& | Bitwise AND | L R | |
10 | ^ | Boolean XOR | L R |
^ | Bitwise XOR | L R | |
11 | | | Boolean OR | L R |
| | Bitwise OR | L R | |
12 | && | Conditional AND | L R |
13 | || | Conditional OR | L R |
14 | ?: | Conditional Ternary Operator | L R |
15 | =,+=,-=, *=,/ =,%=,&=,^=, |=, <<=, >> =, >>>= | Assignment Operators | R L |
No comments:
Post a Comment