Java AtomicInteger getAndAdd( ) method

The getAndAdd() method of Java AtomicInteger class is used to atomically add the given number to the current value.

Syntax

Parameters

delta: It is the value to add.

Return

It returns the previous value.

Example 1

Test it Now

Output:

Updated number is: 100

Example 2

Test it Now

Output:

Updated number is: 20

Example 3

Test it Now

Output:

tUpdated number is: 0

Example 4

Test it Now

Output:

Updated number is: -220

Example 5

Test it Now

Output:

Updated number is: 20





Latest Courses