Java API Tutorial - Java AtomicInteger.get()








Syntax

AtomicInteger.get() has the following syntax.

public final int get()

Example

In the following code shows how to use AtomicInteger.get() method.

import java.util.concurrent.atomic.AtomicInteger;
/*www  .  j  a v a2s.com*/
public class Main {
  public static void main(String[] argv) throws Exception {
    AtomicInteger atomicInteger = new AtomicInteger();
    
    System.out.println(atomicInteger.getAndAdd(10));
    System.out.println(atomicInteger.getAndAdd(10));
    System.out.println(atomicInteger.get());
  }
}

The code above generates the following result.