Java's Operator Precedence

Uniary Operators

  postfix operators             x[] x. (x,y,z) x++ x--
  prefix operators              ++x --x +x -x ~x !x
  creation or cast operators    new x  (type)x

Binary Operators

[these are left-associative]
  multiplicative operators      * / %
  additive operators            + -
  shift operators               << >> >>>
  relational operators          < > >= <= instanceof 
  equality operators            == !=
  bitwise AND                   &
  bitwise exclusive OR          ^
  bitwise inclusive OR          |
  logical AND                   &&
  logical OR                    ||
  conditional operators         ? :

Associative Operators

[these are right-associative]
  =  +=  -=  *=  /=  %=  >>=  <<=  &=  ^=  |=

Use parentheses to override precedence where necessary eg:

while((v = stream.next()) != null)
  process(v);

This page's parent within this Web Site. About this Web Site. Its home page. Email its Author.