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 specified in the object to the current value. It returns the updated value.
public final V updateAndGet(UnaryOperator<V> updateFunction)
Parameters: This method accepts updateFunction which is a side-effect-free function.
Return value: This method returns the updated value.
Below programs illustrate the updateAndGet() method:
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.