Java AtomicInteger decrementAndGet() method

The decrementAndGet() method of Java AtomicInteger class subtracts one from the given value and returns the value after substraction.

Syntax

Return

It returns the updated value.

Example 1

Test it Now

Output:

the value after decrement: 9

Example 2

Test it Now

Output:

the value after decrement: -1

Example 3

Test it Now

Output:

the value after decrement:-3

Example 4

Test it Now

Output:

the value after decrement: -2

Example 5

Test it Now

Output:

the value after decrement: 0





Latest Courses