Java AtomicLong getAndSet() Method

The getAndSet() method of Java AtomicLong class atomically sets the value to newValue and returns the old value

Syntax

Parameters

newValue - the new value

Returns

the previous value

Example 1

Test it Now

Output:

Previous Value : 0
New Value : 10

Example 2

Test it Now

Output:

Previous Value : 5
New Value : 10

Example 3

Test it Now

Output:

Previous Value : -10
New Value : 20

Example 4

Test it Now

Output:

Previous Value : -5
New Value : -10




Latest Courses