AtomicReferenceArray lazySet() method in Java with Examples Last Updated : 03 Jan, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report The lazySet() 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 effects as specified by VarHandle.setRelease(java.lang.Object...) to ensures that prior loads and stores are not reordered after this access. Syntax: public final void lazySet(int i, E newValue) Parameters: This method accepts: i which is an index of AtomicReferenceArray to perform the operation, newValue which is the new value to set. Return value: This method returns nothing. Below programs illustrate the lazySet() method: Program 1: Java // Java program to demonstrate // AtomicReferenceArray.lazySet() method import java.util.concurrent.atomic.*; public class GFG { public static void main(String[] args) { // create an atomic reference object. AtomicReferenceArray<Integer> ref = new AtomicReferenceArray<Integer>(3); // set some value using lazySet() and print ref.lazySet(0, 1234); ref.lazySet(1, 4322); ref.lazySet(2, 2345); System.out.println("Value of index 0 = " + ref.get(0)); System.out.println("Value of index 1 = " + ref.get(1)); System.out.println("Value of index 2 = " + ref.get(2)); } } Output: Program 2: Java // Java program to demonstrate // AtomicReferenceArray.lazySet() method import java.util.concurrent.atomic.*; public class GFG { public static void main(String[] args) { // create an atomic reference object AtomicReferenceArray<String> HIMALAYAN_COUNTRY = new AtomicReferenceArray<String>(5); // set some value HIMALAYAN_COUNTRY.lazySet(0, "INDIA"); HIMALAYAN_COUNTRY.lazySet(1, "CHINA"); HIMALAYAN_COUNTRY.lazySet(2, "PAKISTAN"); HIMALAYAN_COUNTRY.lazySet(3, "BHUTAN"); HIMALAYAN_COUNTRY.lazySet(4, "NEPAL"); // print for (int i = 0; i < 5; i++) { System.out.println( HIMALAYAN_COUNTRY.get(i)); } } } Output: References: https://docs.oracle.com/javase/10/docs/api/java/util/concurrent/atomic/AtomicReferenceArray.html#lazySet(int, E) Comment More infoAdvertise with us Next Article AtomicLongArray lazySet() method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions Java-util-concurrent-atomic package Java-AtomicReferenceArray Practice Tags : Java Similar Reads AtomicReference lazySet() method in Java with Examples The lazySet() 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...) to ensures that prior loads and stores are not reordered after this access. Syntax: public final void lazySet(V newVal 1 min read AtomicReferenceArray length() method in Java with Examples The length() method of a AtomicReferenceArray class is used to return the length of this AtomicReferenceArray. Syntax: public final int length() Parameters: This method accepts nothing. Return value: This method returns the integer representing length of this AtomicReferenceArray. Below programs ill 1 min read AtomicIntegerArray lazySet() method in Java with Examples The Java.util.concurrent.atomic.AtomicIntegerArray.lazySet() is an inbuilt method in Java that eventually sets a given value at any given index of an AtomicIntegerArray. The method takes the index value of the AtomicIntegerArray and the value to set as the parameters and updates the previous value w 2 min read AtomicLongArray lazySet() method in Java with Examples The Java.util.concurrent.atomic.AtomicLongArray.lazySet() is an inbuilt method in Java that eventually sets a given value at any given index of an AtomicLongArray. The method takes the index value of the AtomicLongArray and the value to set as the parameters and updates the previous value without re 2 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 AtomicReferenceArray get() method in Java with Examples The get() method of a AtomicReferenceArray class is used to return the value of the element at index i for this AtomicReferenceArray object with memory semantics of reading as if the variable of index was declared volatile type of variable. Syntax: public final E get(int i) Parameters: This method a 2 min read Like