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.
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.
Thread A 5 Thread A 10 Thread A 15 Thread B 20 Thread B 25 Thread B 30
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.