Java AtomicLong getAndDecrement() Method

The getAndDecrement() method of Java AtomicLong class subtracts 1 from the AtomicLong value and returns its value before the subtraction. This method is equivalent to AtomicLong getAndAdd(-1) method.

Syntax

Returns

the previous value

Example 1

Test it Now

Output:

Previous Value : 0

Example 2

Test it Now

Output:

Previous Value : 10

Example 3

Test it Now

Output:

Previous Value : -20




Latest Courses