The Java.AtomicLong.updateAndGet() method is an inbuilt method, which updates the current value of the object by applying the specified operation on the current value. It takes an object of LongUnaryOperator interface as its parameter and applies the operation specified in the object to the current value. It returns the updated value.
public final long updateAndGet(LongUnaryOperator function)
Parameters: This method accepts as parameter an LongUnaryOperator function. It applies the given function to the current value of the object.
Return Value: The function returns the updated value of the current object.
Example to demonstrate the function.
Initial Value is -20000 Updated value is 20000
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.