AtomicBoolean getAndSet() method in Java with Examples Last Updated : 27 Feb, 2019 Comments Improve Suggest changes Like Article Like Report The Java.util.concurrent.atomic.AtomicBoolean.getAndSet() is an inbuilt method in java that sets the given value to the value passed in the parameter and returns the value before updation which is of data-type boolean. Syntax: public final boolean getAndSet(boolean val) Parameters: The function accepts a single mandatory parameter val which specifies the value to be updated. Return Value: The function returns the value before update operation is performed to the previous value. Below programs illustrate the above method: Program 1: Java // Java program that demonstrates // the getAndSet() function import java.util.concurrent.atomic.AtomicBoolean; public class GFG { public static void main(String args[]) { // Initially value as false AtomicBoolean val = new AtomicBoolean(false); // Updates and sets boolean res = val.getAndSet(true); System.out.println("Previous value: " + res); // Prints the updated value System.out.println("Current value: " + val); } } Output: Previous value: false Current value: true Program 2: Java // Java program that demonstrates // the getAndSet() function import java.util.concurrent.atomic.AtomicBoolean; public class GFG { public static void main(String args[]) { // Initially value as true AtomicBoolean val = new AtomicBoolean(true); // Gets and updates boolean res = val.getAndSet(false); System.out.println("Previous value: " + res); // Prints the updated value System.out.println("Current value: " + val); } } Output: Previous value: true Current value: false Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicBoolean.html#getAndSet-boolean- Comment More infoAdvertise with us Next Article AtomicBoolean getAndSet() method in Java with Examples gopaldave Follow Improve Article Tags : Java Java-Functions Java-concurrent-package Java-AtomicBoolean Practice Tags : Java Similar Reads AtomicBoolean get() method in Java with Examples The java.util.concurrent.atomic.AtomicBoolean.get() is an inbuilt method in java which returns the current value which is of date-type boolean. Syntax: public final boolean get() Parameters: The function does not accepts any parameter. Return Value: The function returns the current value Below progr 1 min read AtomicLong getAndSet() method in Java with examples The Java.util.concurrent.atomic.AtomicLong.getAndSet() is an inbuilt method in java that sets the given value to the value passed in the parameter and returns the value before updation which is of data-type long. Syntax: public final long getAndSet(long val) Parameters: The function accepts a single 2 min read AtomicReference getAndSet() method in Java with Examples The getAndSet() method of a AtomicReference class is used to atomically sets the value of AtomicReference object to newValue which is passed as parameter and returns the old value of the AtomicReference object, with memory effects as specified by VarHandle.getAndSet(java.lang.Object...).VarHandle.ge 2 min read AtomicLongArray getAndSet() method in Java with Examples The Java.util.concurrent.atomic.AtomicLongArray.getAndSet() is an inbuilt method in Java that atomically sets a given value at any given position of the AtomicLongArray. The method takes the index value of the AtomicLongArray and the value to set as the parameters. It returns the value at the given 3 min read AtomicInteger getAndSet() method in Java with examples The java.util.concurrent.atomic.AtomicInteger.getAndSet() is an inbuilt method in java that sets the given value to the value passed in the parameter and returns the value before updation which is of data-type int. Syntax: public final int getAndSet(int val) Parameters: The function accepts a single 2 min read AtomicLong getAndUpdate() method in Java with Examples The Java.AtomicLong.getAndUpdate() 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 1 min read AtomicLong getAndAdd() method in Java with examples The Java.util.concurrent.atomic.AtomicLong.getAndAdd() is an inbuilt method in java that adds the given value to the current value and returns the value before updation which is of data-type long. Syntax: public final long getAndAdd(long val) Parameters: The function accepts a single mandatory param 2 min read AtomicIntegerArray getAndSet() method in Java with Examples The Java.util.concurrent.atomic.AtomicIntegerArray.getAndSet() is an inbuilt method in Java that atomically sets a given value at any given position of the AtomicIntegerArray. The method takes the index value of the AtomicIntegerArray and the value to set as the parameters. It returns the value at t 3 min read AtomicLong get() method in Java with examples The Java.util.concurrent.atomic.AtomicLong.get() is an inbuilt method in java which returns the current value which is of date-type long. Syntax: public final long get() Parameters: The function does not accepts any parameter. Return value: The function returns the current value Below programs illus 1 min read AtomicBoolean set() method in Java with Examples The java.util.concurrent.atomic.AtomicBoolean.set() is an inbuilt method in java that updates the previous value and sets it to a new value which is passed in the parameter. Syntax: public final void set(boolean newVal) Parameters: The function accepts a single mandatory parameter newVal which is to 1 min read Like