AtomicInteger.compareAndSet(int expect, int update) has the following syntax.
public final boolean compareAndSet(int expect, int update)
In the following code shows how to use AtomicInteger.compareAndSet(int expect, int update) method.
import java.util.concurrent.atomic.AtomicInteger; public class Main { public static void main(String[] argv) throws Exception { AtomicInteger atomicInteger = new AtomicInteger(); atomicInteger.compareAndSet(10,10); System.out.println(atomicInteger.decrementAndGet()); } }
The code above generates the following result.