Operator Precedence

Operators are interpreted in order, according to rules.

Apex uses the following operator precedence rules:

PrecedenceOperatorsDescription
1{} () ++ --Grouping and prefix increments and decrements
2~ ! -x +x (type) newUnary operators, additive operators, type cast and object creation
3* /Multiplication and division
4+ -Addition and subtraction
5<< >> >>>Shift Operators
6< <= > >= instanceofGreater-than and less-than comparisons, reference tests
7== !=Comparisons: equal and not-equal
8&Bitwise AND
9^Bitwise XOR
10|Bitwise OR
11&&Logical AND
12||Logical OR
13??Null Coalescing
14?:Ternary
15= += -= *= /= &= <<= >>= >>>=Assignment operators