AtomicLongArray get() method in Java with Examples

The Java.util.concurrent.atomic.AtomicLongArray.get() is an inbuilt method in java that gets the current value at any position of the AtomicLongArray. This method takes the index value as the parameter and returns the value at this index.

Syntax:

public final long 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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

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

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

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

Reference:
https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicLongArray.html#get-int-



My Personal Notes arrow_drop_up

Coder Machine Learner Social Activist Vocalist

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.