AtomicInteger getAndAccumulate() method in Java with Examples
The Java.AtomicInteger.getAndAccumulate() 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 previous value.
public final int getAndAccumulate(int y, IntBinaryOperator function)
Parameters: This method accepts two parameters:
- y: an integer on which the function is to be applied.
- function: function applied to the current value of the object and the value y.
Return Value: The function returns the previous value of the current object.
Example to demonstrate the function.
Thread A 1 Thread A 5 Thread A 25 Thread B 125 Thread B 625 Thread B 3125
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. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.