Java AtomicInteger incrementAndGet() method

The incrementAndGet() method of Java AtomicInteger class increments the value by one and update the old value.

Syntax

Parameters

This will not take any arguments.

Return

It will return the atomicInteger value after incrementing.

Example 1

Test it Now

Output:

the updated number: 1

Example 2

Test it Now

Output:

the updated number: 21

Example 3

Test it Now

Output:

the updated number: 0

Example 4

Test it Now

Output:

the updated number: 3

Example 5

Test it Now

Output:

the updated number: -99





Latest Courses