The following table is a list all operators and their precedence (order of evaluation). Operators with lower level are performed before higher level.

Operators in the same level are evaluated either from left to right or right to left, which is described by associativity. For example, assignment operator (=) have right-to-left associativity; therefore, the expression at the right of the operator is evaluated first, then assigned to the the variable at the left of the operator.

Programmers don’t have to remember the exact precedence. Instead, parentheses can be used to enforce the order of evaluation.

Operator Description Level Associativity
[]

.

()

++

--
access array element

access object member

invoke a method

post-increment

post-decrement
1 left to right
++

--

+

-

!

~
pre-increment

pre-decrement

unary plus

unary minus

logical NOT

bitwise NOT
2 right to left
()

new
cast

object creation
3 right to left
*

/

%
multiplication

division

modulus
4 left to right
+

-
addition, string concatenation

subtraction
5 left to right
<<

>>

>>>
left shift

right shift

unsigned right shift
6 left to right
<

<=

>

>=

instanceof
less than

less than or equal to

greater than

greater than or equal to

type comparison
7 left to right
==

!=
equality 8 left to right
& bitwise AND 9 left to right
^ bitwise XOR 10 left to right
| bitwise OR 11 left to right
&& conditional AND 12 left to right
|| conditional OR 13 left to right
?: conditional 14 right to left
=

+=

-=

*=

/=

%=

&=

^=

|=

<<=

>>=

>>>=
assignment 15 right to left