C.12 Increment and Decrement Operators

Java provides two unary operators (summarized in Fig. C.10) for adding 1 to or subtracting 1 from the value of a numeric variable. These are the unary increment operator, ++, and the unary decrement operator, --. A program can increment by 1 the value of a variable

Fig. C.10 Increment and decrement operators

Operator Operator name Sample expression Explanation
++

prefix

increment

++a Increment a by 1, then use the new value of a in the expression in which a resides.
++

postfix

increment

a++ Use the current value of a in the expression in which a resides, then increment a by 1.
--

prefix

decrement

--b Decrement b by 1, then use the new value of b in the expression in which b resides.
--

postfix ...

Get Android How to Program, 3/e 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.