Java operator priority
Regarding the Java operator priority order, first of all, Java is a strongly typed language, and the operator priority has strict regulations. Operators are run in order of priority first, and then from left to right.
In normal Java operation development, it is actually better to bring parentheses, but we still need to understand the operator priority very well. See the list below for details.
Priority | Operator | Introduction | Associativity |
---|---|---|---|
1 | [ ] 、 . 、 ( ) | Method call, property acquisition | From left to right |
2 | !、~、 ++、 -- | Unary operators | right to left |
3 | * , / , % | Multiplication, division, modulo (remainder) | left to right |
4 | + , - | Addition and subtraction | left to right |
5 | <<, >>, >>> | Left shift, right shift, unsigned right shift | left to right |
6 | < , <= , >, >=, instanceof | Less than, less than or equal to, greater than, greater than or equal to, Object type judgment whether it belongs to the same type | From left to right |
7 | == , != | Whether two values are equal, whether two values are not equal. Detailed explanation below | Left to Right |
8 | & | Bitwise AND | Left to Right |
9 | ^ | Bitwise XOR | Left to Right |
10 | | | Bitwise OR | Left to Right |
11 | && | Short Circuit AND | Left to Right |
12 | || | Short-Circuiting OR | Left to Right |
13 | ?: | Conditional Operator | Right to Left |
14 | =, += , -= , *= , /=, %=, &=, |=, ^=, <, <= , >, >= , >>= | Mixed Assignment Operators | Right to Left |