Java API Tutorial - Java AtomicInteger .getAndIncrement ()








Syntax

AtomicInteger.getAndIncrement() has the following syntax.

public final int getAndIncrement()

Example

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

/*ww  w.ja v  a2 s. c om*/
import java.util.concurrent.atomic.AtomicInteger;

public class Main {
  public static void main(String[] argv) throws Exception {
    AtomicInteger atomicInteger = new AtomicInteger();
    
    System.out.println(atomicInteger.getAndIncrement());
  }
}

The code above generates the following result.