Java AtomicInteger addAndGet() method

The addAndGet() method of Java AtomicInteger class atomically adds the given value to the current value.

Syntax

Parameters

delta - It is the value to add

Return

It returns the updated value.

Example 1

Test it Now

Output:

when initial value is 0: 2

Example 2

Test it Now

Output:

when initial value is 100: 102

Example 3

Test it Now

Output:

when initial value is 100: -100

Example 4

Test it Now

Output:

when initial value is -100: -94

Example 5

Test it Now

Output:

when initial value is -100: -200





Latest Courses