The Java.util.concurrent.atomic.AtomicLong.getAndDecrement() is an inbuilt method in java that decreases the given value by one and returns the value before updation which is of data-type long.
Syntax:
public final long getAndDecrement()
Parameters: The function does not accepts a single parameter.
Return value: The function returns the value before decrement operation is performed to the previous value.
Below programs illustrate the above method:
Program 1:
| // Java program that demonstrates// the getAndDecrement() function Âimportjava.util.concurrent.atomic.AtomicLong; ÂpublicclassGFG {    publicstaticvoidmain(String args[])    { Â        // Initially value as 0        AtomicLong val            = newAtomicLong(0); Â        // Decreases and gets        // the previous value        longres            = val.getAndDecrement(); Â        // Prints the updated value        System.out.println("Previous value: "                           + res); Â        System.out.println("Current value: "                           + val);    }} | 
Previous value: 0 Current value: -1
Program 2:
| // Java program that demonstrates// the getAndDecrement() function Âimportjava.util.concurrent.atomic.AtomicLong; ÂpublicclassGFG {    publicstaticvoidmain(String args[])    { Â        // Initially value as 18        AtomicLong val            = newAtomicLong(18); Â        // Decreases 1 and gets        // the previous value        longres = val.getAndDecrement(); Â        // Prints the updated value        System.out.println("Previous value: "                           + res); Â        System.out.println("Current value: "                           + val);    }} | 
Previous value: 18 Current value: 17


 
                                    







