An AtomicInteger
represents an integer value that can update atomically.
An atomic operation performs a single unit of work on a resource. Other operations are not allowed on the same resource until the first operation is finished.
The AtomicInteger
class is present in the java.util.concurrent.atomic
package.
This article may help us better understand the Atomic concept.
We use the get
method of the AtomicInteger
to get the value present in the AtomicInteger
object.
public final int get()
This method takes no arguments.
This method returns the value present in the AtomicInteger
object.
The below code demonstrates how to use the get
method:
import java.util.concurrent.atomic.AtomicInteger;class Get{public static void main(String[] args) {AtomicInteger atomicInteger = new AtomicInteger(10);int val = atomicInteger.get();System.out.println("The value in the atomicInteger object is " + val);}}
AtomicInteger
class.AtomicInteger
class, with the name atomicInteger
and the value 10
.get
method of the atomicInteger
, store it to the integer variable val
, and then print the value.