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.
public final int addAndGet(int val)
Parameters: The function accepts a single mandatory parameter val which specifies the value to be added.
Return value: The function returns the integer value after addition is done.
Program below demonstrates the function:
Updated value: 6
Previous value: 18 Updated value: 24
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.