AtomicLongArray get() method in Java with Examples
Last Updated :
05 Feb, 2019
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:
import java.util.concurrent.atomic.AtomicLongArray;
public class GFG {
public static void main(String args[])
{
long a[] = { 1 , 2 , 3 , 4 , 5 };
AtomicLongArray arr = new AtomicLongArray(a);
System.out.println( "The array : " + arr);
int idx = 2 ;
long val = arr.get(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:
import java.util.concurrent.atomic.AtomicLongArray;
public class GFG {
public static void main(String args[])
{
long a[] = { 12 , 22 , 23 , 24 , 25 };
AtomicLongArray arr = new AtomicLongArray(a);
System.out.println( "The array : " + arr);
int idx = 4 ;
long val = arr.get(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/8/docs/api/java/util/concurrent/atomic/AtomicLongArray.html#get-int-
Share your thoughts in the comments
Please Login to comment...