Java AtomicLongArray.getAndSet(int i, long newValue)

Syntax

AtomicLongArray.getAndSet(int i, long newValue) has the following syntax.

public final long getAndSet(int i,  long newValue)

Example

In the following code shows how to use AtomicLongArray.getAndSet(int i, long newValue) method.


import java.util.concurrent.atomic.AtomicLongArray;
//  w w  w  .  j  a  v  a 2  s  . com
public class Main {
  public static void main(String[] argv) throws Exception {
    AtomicLongArray atomicLongArray = new AtomicLongArray(10);
    System.out.println(atomicLongArray.getAndSet(2,10L));
    System.out.println(atomicLongArray.get(0));
  }
}

The code above generates the following result.





















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




AtomicBoolean
AtomicInteger
AtomicIntegerArray
AtomicLong
AtomicLongArray