Precedence table


Precedence rules tell in what order operations are done. For example, the rules tell you that 2+3*4 is 14, not 20.

Every programmer should know the basic rules of precedence. For operators not covered by the basic rules, it is considered good style to use parentheses to indicate the order of operations, even when those parentheses are not necessary; this makes your code more readable by programmers who do not have the following table memorized.

Entries nearer the top of the table have higher precedence (are done first); entries on the same line of the table have equal precedences.

Operators Meanings
(parameters) [indices] . expr++ expr-- Method call, array index, field/method access, postincrement, postdecrement
++expr --expr +expr -expr ! ~ Preincrement, predecrement, unary plus, unary minus, not, bitwise complement
new  (type)expr Constructor call, cast
* / % Multiply, divide, modulus
+ - Add, subtract
<< >> >>> Left shift, right shift, right shift with zero fill
< > <= >= instanceof Less than, greater than, less than or equal to, greater than or equal to, class or interface membership
== != Test if equal, test if not equal
& Bitwise and
^ Bitwise exclusive or
| Bitwise or
&& Logical and
|| Logical or
condition ? expr : expr Shortcut if-else
+= -= *= /= %=
^= &= |= <<= >>=
simple assignment,
assignment with operation