3.7. Variable Increment and Decrement Operators: ++, --

Variable increment (++) and decrement (--) operators come in two flavors: prefix and postfix. These unary operators have the side effect of changing the value of the arithmetic operand, which must evaluate to a variable. Depending on the operator used, the variable is either incremented or decremented by 1.

These operators are very useful for updating variables in loops where only the side effect of the operator is of interest.

Increment Operator ++

Prefix increment operator has the following semantics:

++i adds 1 to i first, then uses the new value of i as the value of the expression. It is equivalent to the following statements.

i += 1;
result = i;
return result;

Postfix increment operator ...

Get Programmer's Guide to Java™ Certification, A: A Comprehensive Primer, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.