Java API Tutorial - Java AtomicInteger.set(int newValue)








Syntax

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

public final void set(int newValue)

Example

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

//from www.jav a 2  s .co  m
import java.util.concurrent.atomic.AtomicInteger;

public class Main {
  public static void main(String[] argv) throws Exception {
    AtomicInteger atomicInteger = new AtomicInteger();
    
    atomicInteger.set(2);
    
    System.out.println(atomicInteger);
  }
}

The code above generates the following result.