AtomicInteger accumulateAndGet() method in Java with Examples Last Updated : 04 Feb, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report The Java.AtomicInteger.accumulateAndGet() method is an inbuilt method, which updates the current value of the object by applying the specified operation on the current value and value passed as a parameter. It takes an integer as its parameter and an object of IntBinaryOperator interface and applies the operation specified in the object to the values. It returns the updated value. Syntax: public final int accumulateAndGet(int y, IntBinaryOperator function) Parameters: This method accepts as parameter an integer value y and an IntBinaryOperator function. It applies the given function to the current value of the object and the value y. Return Value: The function returns the updated value of the current object. Example to demonstrate the function. Java // Java program to demonstrate // AtomicInteger accumulateAndGet() method import java.util.concurrent.atomic.AtomicInteger; import java.util.function.IntBinaryOperator; public class Demo { public static void main(String[] args) { new UserThread("Thread A"); new UserThread("Thread B"); } } class Shared { static AtomicInteger ai = new AtomicInteger(0); } class UserThread implements Runnable { String name; UserThread(String name) { this.name = name; new Thread(this).start(); } IntBinaryOperator ibo = (x, y) -> (x + y); int value = 5; @Override public void run() { for (int i = 0; i < 3; i++) { int ans = Shared.ai .accumulateAndGet(value, ibo); System.out.println(name + " " + ans); } } } Output: Thread A 5 Thread A 10 Thread A 15 Thread B 20 Thread B 25 Thread B 30 Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicInteger.html Comment More infoAdvertise with us Next Article AtomicReference accumulateAndGet() 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 accumulateAndGet() method in Java with Examples The Java.util.concurrent.atomic.AtomicIntegerArray.accumulateAndGet() is an inbuilt method in java that atomically updates the element at index i with the results of applying the given function to the current and given values, returning the updated value. The function should be side-effect-free, sin 3 min read AtomicLong accumulateAndGet() method in Java with Examples The Java.AtomicLong.accumulateAndGet() method is an inbuilt method, which updates the current value of the object by applying the specified operation on the current value and value passed as a parameter. It takes a long as its parameter and an object of LongBinaryOperator interface and applies the o 2 min read AtomicReference accumulateAndGet() method in Java with Examples The accumulateAndGet() method of a AtomicReference class is used to atomically updates the current value of AtomicReference with the results of applying the given accumulatorFunction to the current and given values and returns the updated value. The accumulatorFunction should be side-effect-free, si 2 min read AtomicLongArray accumulateAndGet() method in Java with Examples The Java.util.concurrent.atomic.AtomicLongArray.accumulateAndGet() is an inbuilt method in java that atomically updates the element at index i with the results of applying the given function to the current and given values, returning the updated value. The function should be side-effect-free, since 3 min read AtomicInteger addAndGet() method in Java with examples The java.util.concurrent.atomic.AtomicInteger.addandget() is an inbuilt method in java which adds the value which is passed in the parameter of the function to the previous value and returns the new updated value which is of data-type int. Syntax: public final int addAndGet(int val) Parameters: The 2 min read AtomicReferenceArray accumulateAndGet() method in Java with Examples The accumulateAndGet() method of a AtomicReferenceArray class is used to atomically updates the element at index i of AtomicReferenceArray with the results of applying the given accumulatorFunction to the current and given values and returns the updated value. The accumulatorFunction should be side- 2 min read Like