AtomicInteger updateAndGet() method in Java with Examples Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The Java.AtomicInteger.updateAndGet() method is an inbuilt method, which updates the current value of the object by applying the specified operation on the current value. It takes an object of IntUnaryOperator interface as its parameter and applies the operation specified in the object to the current value. It returns the updated value. Syntax: public final int updateAndGet(IntUnaryOperator function) Parameters: This method accepts as parameter an IntUnaryOperator function. It applies the given function to the current value of the object. Return Value: The function returns the updated value of the current object. Example to demonstrate the function. Program 1: Java // Java program to demonstrate the above function import java.util.concurrent.atomic.AtomicInteger; import java.util.function.IntUnaryOperator; public class Demo { public static void main(String[] args) { // Atomic Integer initialized with a value of 10 AtomicInteger ai = new AtomicInteger(10); // Unary operator defined to negate the value IntUnaryOperator unaryOperator = (x) -> - x; System.out.println("Initial Value is " + ai); // Function called and the unary operator // is passed as an argument int x = ai.updateAndGet(unaryOperator); System.out.println("Updated value is " + x); } } Output: Initial Value is 10 Updated value is -10 Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicInteger.html Comment More infoAdvertise with us Next Article AtomicLong updateAndGet() method in Java with Examples C CharchitKapoor Follow Improve Article Tags : Java Java-Functions Java-AtomicInteger Java-util-concurrent-atomic package Practice Tags : Java Similar Reads AtomicIntegerArray updateAndGet() method in Java with Examples The Java.util.concurrent.atomic.AtomicIntegerArray.updateAndGet() is an inbuilt method in Java that updates the value at any given index of the AtomicIntegerArray after applying a given update function on the value at that index. The method takes the index value of the AtomicIntegerArray and the upd 3 min read AtomicLong updateAndGet() method in Java with Examples The Java.AtomicLong.updateAndGet() method is an inbuilt method, which updates the current value of the object by applying the specified operation on the current value. It takes an object of LongUnaryOperator interface as its parameter and applies the operation specified in the object to the current 1 min read AtomicLong updateAndGet() method in Java with Examples The Java.AtomicLong.updateAndGet() method is an inbuilt method, which updates the current value of the object by applying the specified operation on the current value. It takes an object of LongUnaryOperator interface as its parameter and applies the operation specified in the object to the current 1 min read AtomicReference updateAndGet() method in Java with Examples The updateAndGet() method of a AtomicReference class is used to atomically updates which updates the current value of the AtomicReference by applying the specified updateFunction operation on the current value. It takes an object of updateFunction interface as its parameter and applies the operation 2 min read AtomicLongArray updateAndGet() method in Java with Examples The Java.util.concurrent.atomic.AtomicLongArray.updateAndGet() is an inbuilt method in Java that updates the value at any given index of the AtomicLongArray after applying a given update function on the value at that index. The method takes the index value of the AtomicLongArray and the update funct 3 min read AtomicInteger set() method in Java with examples The java.util.concurrent.atomic.AtomicInteger.set() is an inbuilt method in java that updates the previous value and sets it to a new value which is passed in the parameter. Syntax: public final void set(int newVal) Parameters: The function accepts a single mandatory parameter newVal which is to be 1 min read Like