AtomicIntegerArray addAndGet() method in Java with Examples Last Updated : 27 Feb, 2019 Comments Improve Suggest changes Like Article Like Report The Java.util.concurrent.atomic.AtomicIntegerArray.addAndGet() is an inbuilt method in Java that atomically adds the given value to the element at an index of the AtomicIntegerArray. This method takes the index value and the value to be added as the parameters and returns the updated value at this index. Syntax: public int addAndGet(int i, int delta) Parameters: The function accepts two parameters: i - The index where value is to be added. delta - The value to be added. Return value: The function returns the updated value which is in Integer. Below programs illustrate the above method: Program 1: Java // Java program that demonstrates // the addAndGet() function import java.util.concurrent.atomic.AtomicIntegerArray; public class GFG { public static void main(String args[]) { // Initializing an array int a[] = { 10, 22, 33, 44, 55 }; // Initializing an AtomicIntegerArray with array a AtomicIntegerArray arr = new AtomicIntegerArray(a); // Displaying the AtomicIntegerArray System.out.println("The array : " + arr); // Index where value is to be added int idx = 0; // Value to add with value at idx int x = 16; // Updating the value at // idx applying addAndGet arr.addAndGet(idx, x); // Displaying the AtomicIntegerArray System.out.println("The array after update : " + arr); } } Output: The array : [10, 22, 33, 44, 55] The array after update : [26, 22, 33, 44, 55] Program 2: Java // Java program that demonstrates // the addAndGet() function import java.util.concurrent.atomic.AtomicIntegerArray; public class GFG { public static void main(String args[]) { // Initializing an array int a[] = { 1, 2, 3, 4, 5 }; // Initializing an AtomicIntegerArray with array a AtomicIntegerArray arr = new AtomicIntegerArray(a); // Displaying the AtomicIntegerArray System.out.println("The array : " + arr); // Index where value is to be added int idx = 3; // Value to add with value at idx int x = 16; // Updating the value at // idx applying addAndGet arr.addAndGet(idx, x); // Displaying the AtomicIntegerArray System.out.println("The array after update : " + arr); } } Output: The array : [1, 2, 3, 4, 5] The array after update : [1, 2, 3, 20, 5] Reference: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/atomic/AtomicIntegerArray.html#addAndGet(int, %20int) Comment More infoAdvertise with us Next Article AtomicIntegerArray addAndGet() method in Java with Examples gopaldave Follow Improve Article Tags : Java Java-Functions Java-concurrent-package Java-AtomicIntegerArray Practice Tags : Java Similar Reads AtomicInteger addAndGet() method in Java with examples The java.util.concurrent.atomic.AtomicInteger.addandget() is an inbuilt method in java which adds the value which is passed in the parameter of the function to the previous value and returns the new updated value which is of data-type int. Syntax: public final int addAndGet(int val) Parameters: The 2 min read AtomicLongArray addAndGet() method in Java with Examples The Java.util.concurrent.atomic.AtomicLongArray.addAndGet() is an inbuilt method in Java that atomically adds the given value to the element at an index of the AtomicLongArray. This method takes the index value and the value to be added as the parameters and returns the updated value at this index. 2 min read AtomicIntegerArray accumulateAndGet() method in Java with Examples The Java.util.concurrent.atomic.AtomicIntegerArray.accumulateAndGet() is an inbuilt method in java that atomically updates the element at index i with the results of applying the given function to the current and given values, returning the updated value. The function should be side-effect-free, sin 3 min read AtomicLong addAndGet() method in Java with examples The Java.util.concurrent.atomic.AtomicLong.addandget() is an inbuilt method in java which adds the value which is passed in the parameter of the function to the previous value and returns the new updated value which is of data-type long. Syntax: public final long addAndGet(long val) Parameters: The 2 min read AtomicIntegerArray get() method in Java with Examples The Java.util.concurrent.atomic.AtomicIntegerArray.get() is an inbuilt method in java that gets the current value at any position of the AtomicIntegerArray. This method takes the index value as the parameter and returns the value at this index. Syntax: public final int get(int i) Parameters: The fun 2 min read AtomicIntegerArray set() method in Java with Examples The Java.util.concurrent.atomic.AtomicIntegerArray.set() is an inbuilt method in Java that sets a given value at any position of the AtomicIntegerArray. This method takes the index value of the AtomicIntegerArray as parameter and updates the value at that index. This method does not return any value 2 min read AtomicInteger accumulateAndGet() method in Java with Examples The Java.AtomicInteger.accumulateAndGet() method is an inbuilt method, which updates the current value of the object by applying the specified operation on the current value and value passed as a parameter. It takes an integer as its parameter and an object of IntBinaryOperator interface and applies 2 min read AtomicLongArray accumulateAndGet() method in Java with Examples The Java.util.concurrent.atomic.AtomicLongArray.accumulateAndGet() is an inbuilt method in java that atomically updates the element at index i with the results of applying the given function to the current and given values, returning the updated value. The function should be side-effect-free, since 3 min read AtomicIntegerArray length() method in Java with Examples The Java.util.concurrent.atomic.AtomicIntegerArray.length() is an inbuilt method in Java that returns the length of the AtomicIntegerArray. This method does not accepts any parameter and returns the length of the AtomicIntegerArray which is of type int. Syntax: public final int length() Parameters: 2 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 Like