Java API Tutorial - Java AtomicLong.addAndGet(long delta)








Syntax

AtomicLong.addAndGet(long delta) has the following syntax.

public final long addAndGet(long delta)

Example

In the following code shows how to use AtomicLong.addAndGet(long delta) method.

import java.util.concurrent.atomic.AtomicLong;
//from  ww w.  j  ava2s  .c om
public class Main {
  public static void main(String[] argv) {
    AtomicLong nextId = new AtomicLong();

    System.out.println(nextId.getAndIncrement());
    System.out.println(nextId.addAndGet(100L));
  }
}

The code above generates the following result.