Java API Tutorial - Java AtomicInteger.getAndAdd(int delta)








Syntax

AtomicInteger.getAndAdd(int delta) has the following syntax.

public final int getAndAdd(int delta)

Example

In the following code shows how to use AtomicInteger.getAndAdd(int delta) method.

import java.util.concurrent.atomic.AtomicInteger;
//from  w  w w  .j a  v a 2  s  .co m
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));
  }
}

The code above generates the following result.