Java AtomicLongArray length()方法及示例
Java.util.concurrent.atomic.AtomicLongArray.length() 是Java中一个内置的方法,用于返回AtomicLongArray的长度。该方法不接受任何参数,并返回类型为int的AtomicLongArray的长度。
语法
public final int length()
参数: 该函数不接受任何参数。
返回值: 该函数返回AtomicLongArray的长度。
下面的程序说明了上述方法。
程序1 :
// Java program that demonstrates
// the length() function
import java.util.concurrent.atomic.AtomicLongArray;
public class GFG {
public static void main(String args[])
{
// Initializing an array
long a[] = { 11, 12, 13, 14, 15 };
// Initializing an AtomicLongArray with array a
AtomicLongArray arr = new AtomicLongArray(a);
// Displaying the length of the AtomicLongArray
System.out.println("The length of the array : "
+ arr.length());
}
}
输出。
The length of the array : 5
程序2
// Java program that demonstrates
// the length() function
import java.util.concurrent.atomic.AtomicLongArray;
public class GFG {
public static void main(String args[])
{
// Initializing an array
long a[] = { 11, 12, 13, 14, 15, 16, 17 };
// Initializing an AtomicLongArray with array a
AtomicLongArray arr = new AtomicLongArray(a);
// Displaying the length of the AtomicLongArray
System.out.println("The length of the array : "
+ arr.length());
}
}
输出。
The length of the array : 7
参考资料:
https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicLongArray.html#length-