📌  相关文章
📜  Java中的 AtomicLongArray length() 方法及示例

📅  最后修改于: 2022-05-13 01:54:50.674000             🧑  作者: Mango

Java中的 AtomicLongArray length() 方法及示例

Java.util.concurrent.atomic.AtomicLongArray.length()是Java中的一个内置方法,它返回 AtomicLongArray 的长度。此方法不接受任何参数,并返回int类型的 AtomicLongArray 的长度。

句法:

参数:该函数不接受任何参数。

返回值:函数返回 AtomicLongArray 的长度。

下面的程序说明了上述方法:

方案一:

// 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

方案二:

// 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 Java