Java API Tutorial - Java AtomicBoolean .getAndSet (boolean newValue)








Syntax

AtomicBoolean.getAndSet(boolean newValue) has the following syntax.

public final boolean getAndSet(boolean newValue)

Example

In the following code shows how to use AtomicBoolean.getAndSet(boolean newValue) method.

/*from  ww  w .ja va  2  s.  com*/
import java.util.concurrent.atomic.AtomicBoolean;

public class Main {
  public static void main(String[] argv) throws Exception {
    AtomicBoolean atomicBoolean = new AtomicBoolean();
    
   
    System.out.println(atomicBoolean.getAndSet(true));
  }
}

The code above generates the following result.