Java AtomicInteger.getAndSet(int newValue)

Syntax

AtomicInteger.getAndSet(int newValue) has the following syntax.

public final int getAndSet(int newValue)

Example

In the following code shows how to use AtomicInteger.getAndSet(int newValue) method.


import java.util.concurrent.atomic.AtomicInteger;
/*from  w w  w.j a v  a  2s. c om*/
public class Main {
  public static void main(String[] argv) throws Exception {
    AtomicInteger atomicInteger = new AtomicInteger();
    
    System.out.println(atomicInteger.getAndSet(10));
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.util.concurrent.atomic »




AtomicBoolean
AtomicInteger
AtomicIntegerArray
AtomicLong
AtomicLongArray