import java.util.concurrent.atomic.AtomicLong; public class TestAtomicLong { private static AtomicLong counter = new AtomicLong(0); public static void main(String[] args) { System.out.println("Counter: " + counter.getAndSet(10)); //prints 0 System.out.println("Counter: " + counter.get()); //prints 10 } }In this example, we create an instance of AtomicLong with an initial value of 0, and then use the getAndSet method to set its value to 10 and retrieve the previous value of 0. The output confirms that the operation was performed atomically. Package library: java.util.concurrent.atomic