Java AtomicLong getAndIncrement() Method

The getAndAdd() method of Java AtomicLong class return current value and increments current value by 1. This method is equivalent to AtomicLong getAndAdd(1) method.

Syntax

Returns

the previous value

Example 1

Test it Now

Output:

Return Value : 0
Incremented Value : 1

Example 2

Test it Now

Output:

Return Value : 10
Incremented Value : 11

Example 3

Test it Now

Output:

Return Value : -20
Incremented Value : -19




Latest Courses