Java Operator Precedence
Java Operator Precedence
higher precedence
x++ x-- ~x decrement, bitwise negation
prefix increment, prefix
decrement, unary positive,
++x --x +x -x !x unary negative, logical
negation right-associative
multiplication, division,
* / % modulus
Gosling, James, et al. The Java Language Specification, 3e. Addison-Wesley, 2005.
addition, subtraction, string
x+y x-y x+"x"
^ bitwise XOR
sources:
| bitwise OR
|| logical OR
x ? y : z ternary (conditional)
= right-associative
+= -= *= /= %= assignment and compound
<<= >>= >>>= assignment
&= ^= |=
Note: operators with the same precedence level in an expression are evaluated based on their associativity. For example,
left-associative operators group from left to right. Therefore, the expression x * y % z is equivalent to (x * y) % z.