Java API Tutorial - Java AtomicLong.decrementAndGet()








Syntax

AtomicLong.decrementAndGet() has the following syntax.

public final long decrementAndGet()

Example

In the following code shows how to use AtomicLong.decrementAndGet() method.

/*  ww  w  .  ja  v  a2s  .  co  m*/
import java.util.concurrent.atomic.AtomicLong;

public class Main {
  public static void main(String[] argv) {
    AtomicLong nextId = new AtomicLong();

    System.out.println(nextId.getAndIncrement());
    System.out.println(nextId.decrementAndGet());
  }
}

The code above generates the following result.