Junior — Middle
How to determine the time costs when adding an element to an ArrayList?
sobes.tech AI
Answer from AI
The increment operation on a variable in Java is called increment. It is performed using the ++ operator.
There are two usage options:
- Prefix increment (
++var) — increases the value of the variable first, then returns the new value. - Postfix increment (
var++) — returns the current value of the variable, then increases it.
Example:
int a = 5;
int b = ++a; // a becomes 6, b is also 6
int c = 5;
int d = c++; // d will be 5, c becomes 6 after the operation
Increment is often used in loops and counters for convenient increase of value by 1.