當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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–



相關用法


注:本文由純淨天空篩選整理自rupesh_rao大神的英文原創作品 AtomicLongArray length() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。