Java AtomicInteger getAndDecrement() method

The getAndDecrement() method in AtomicInteger class gets the current value and decrement it by one. But it returns the value of atomicInteger before the subtraction.

Syntax

Return

It will return the currentValue first and decrement.

Example 1

Test it Now

Output:

the updated number: 19

Example 2

Test it Now

Output:

the updated number: -1

Example 3

Test it Now

Output:

the updated number: 9

Example 4

Test it Now

Output:

the updated number: -2

Example 5

Test it Now

Output:

the updated number: -11





Latest Courses