AtomicBoolean set() method in Java with Examples Last Updated : 27 Feb, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 be updated. Return Value: The function does not returns anything. Below programs illustrate the above function: Program 1: Java // Java program that demonstrates // the set() 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); System.out.println("Previous value: " + val); val.set(true); // 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 set() 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); System.out.println("Previous value: " + val); val.set(false); // 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#set-boolean- Comment More infoAdvertise with us Next Article AtomicBoolean lazySet() method in Java with Examples G gopaldave Follow Improve Article Tags : Java Java-Functions Java-concurrent-package Java-AtomicBoolean Practice Tags : Java Similar Reads AtomicLong set() method in Java with examples The Java.util.concurrent.atomic.AtomicLong.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(long newVal) Parameters: The function accepts a single mandatory parameter newVal which is to be up 1 min read AtomicBoolean lazySet() method in Java with Examples The java.util.concurrent.atomic.AtomicBoolean.lazySet() 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 lazySet(boolean newVal) Parameters: The function accepts a single mandatory parameter newVal whi 1 min read Set clear() method in Java with Examples The Java.util.Set.clear() method is used to remove all the elements from a Set. Using the clear() method only clears all the element from the set and not deletes the set. In other words, we can say that the clear() method is used to only empty an existing Set. Syntax: void clear() Parameters: The me 1 min read AtomicInteger set() method in Java with examples The java.util.concurrent.atomic.AtomicInteger.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(int newVal) Parameters: The function accepts a single mandatory parameter newVal which is to be 1 min read AtomicReference set() method in Java with Examples The set() method of a AtomicReference class is used to set the value of this AtomicReference object with memory semantics of reading as if the variable was declared volatile type of variable. Syntax: public final void set(V newValue) Parameters: This method accepts newValue which is the new value to 1 min read AtomicLongArray set() method in Java with Examples The Java.util.concurrent.atomic.AtomicLongArray.set() is an inbuilt method in Java that sets a given value at any position of the AtomicLongArray. This method takes the index value of the AtomicLongArray as parameter and updates the value at that index. This method does not return any value. The fun 2 min read Like