AtomicReference set() method in Java with Examples Last Updated : 27 Dec, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 set. Return value: This method returns nothing. Below programs illustrate the set() method: Program 1: Java // Java program to demonstrate // AtomicReference.set() method import java.util.concurrent.atomic.AtomicReference; public class GFG { public static void main(String[] args) { // create an atomic reference object // which stores Integer. AtomicReference<Integer> ref = new AtomicReference<Integer>(); // set some value using set method ref.set(13243546); // print value System.out.println("value 1 = " + ref.get()); } } Output: value 1 = 13243546 Program 2: Java // Java program to demonstrate // AtomicReference.set() method import java.util.concurrent.atomic.AtomicReference; public class GFG { public static void main(String[] args) { // create an atomic reference object // which stores String. AtomicReference<String> ref = new AtomicReference<String>(); // set some value ref.set("WELCOME TO GEEKS FOR GEEKS"); // print value System.out.println("V = " + ref.get()); } } Output: V = WELCOME TO GEEKS FOR GEEKS References: https://docs.oracle.com/javase/10/docs/api/java/util/concurrent/atomic/AtomicReference.html#set(V) Comment More infoAdvertise with us Next Article AtomicReference set() method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions Java-util-concurrent-atomic package Practice Tags : Java Similar Reads AtomicReference setPlain() method in Java with Examples The setPlain() method of a AtomicReference class is used to set the value of this AtomicReference object with memory semantics of setting as if the variable was declared non-volatile and non-final. Syntax: public final void setPlain(V newValue) Parameters: This method accepts newValue which is the n 1 min read AtomicReferenceArray set() method in Java with Examples The set() method of a AtomicReferenceArray class is used to set the value of the element at index i to newValue. Both index i and newValue are passed as parameters to the method. This method set the value with memory semantics of reading as if the variable was declared volatile type of variable. Syn 2 min read AtomicReference setOpaque() method in Java with Examples The setOpaque() method of a AtomicReference class is used to set the value of this AtomicReference object with memory effects as specified by VarHandle.setOpaque(java.lang.Object...). In this way value is set in program order, but with no assurance of memory ordering effects with respect to other th 1 min read AtomicReference toString() method in Java with Examples The toString() method of a AtomicReference class is used to return the String representation of the current value of AtomicReference object. Syntax: public String toString() Parameters: This method accepts nothing. Return value: This method returns the String representation of the current value. Bel 1 min read AtomicReference setRelease() method in Java with Examples The setRelease() method of a AtomicReference class is used to set the value of this AtomicReference object with memory effects as specified by VarHandle.setRelease(java.lang.Object...). This method has memory ordering effects compatible with memory_order_release ordering. Syntax: public final void s 1 min read Like