Skip to content
Related Articles

Related Articles

AtomicIntegerArray get() method in Java with Examples

View Discussion
Improve Article
Save Article
  • Last Updated : 27 Feb, 2019
View Discussion
Improve Article
Save Article

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 function accepts a single parameter i i.e the value of index to get.

Return value: The function returns the current value at index i.

Below programs illustrate the above method:

Program 1:




// Java program that demonstrates
// the get() 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 to get
        int idx = 2;
  
        // Using get() to retrieve value at idx
        int val = arr.get(idx);
  
        // Displaying the value at idx
        System.out.println("Value at index " + idx
                           + " is " + val);
    }
}


Output:

The array : [1, 2, 3, 4, 5]
Value at index 2 is 3

Program 2:




// Java program that demonstrates
// the get() function
  
import java.util.concurrent.atomic.AtomicIntegerArray;
  
public class GFG {
    public static void main(String args[])
    {
        // Initializing an array
        int a[] = { 12, 22, 23, 24, 25 };
  
        // Initializing an AtomicIntegerArray with array a
        AtomicIntegerArray arr = new AtomicIntegerArray(a);
  
        // Displaying the AtomicIntegerArray
        System.out.println("The array : " + arr);
  
        // Index to get
        int idx = 4;
  
        // Using get() to retrieve value at idx
        int val = arr.get(idx);
  
        // Displaying the value at idx
        System.out.println("Value at index " + idx
                           + " is " + val);
    }
}


Output:

The array : [12, 22, 23, 24, 25]
Value at index 4 is 25

Reference: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/atomic/AtomicIntegerArray.html#get(int)


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!