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


Java AtomicReferenceArray length()用法及代碼示例


AtomicReferenceArray類的length()方法用於返回此AtomicReferenceArray的長度。

用法:

public final int length()

參數:此方法不接受任何內容。


返回值:此方法返回表示此AtomicReferenceArray長度的整數。

以下示例程序旨在說明length()方法:
程序1:

// Java program to demonstrate 
// AtomicReferenceArray.length() method 
  
import java.util.concurrent.atomic.*; 
  
public class GFG { 
  
    public static void main(String[] args) 
    { 
  
        // create an atomic reference object. 
        AtomicReferenceArray<Integer> ref 
            = new AtomicReferenceArray<Integer>(5); 
  
        // print the length 
        int length = ref.length(); 
        System.out.println( 
            "length of AtomicReferenceArray = "
            + length); 
    } 
}
輸出:
length of AtomicReferenceArray = 5

程序2:

// Java program to demonstrate 
// AtomicReferenceArray.length() method 
  
import java.util.concurrent.atomic.*; 
  
public class GFG { 
  
    public static void main(String[] args) 
    { 
  
        // create a array of Strings 
        String[] names 
            = { "AMAN", "AMAR", "SURAJ" }; 
  
        // create an atomic reference object. 
        AtomicReferenceArray<String> ref 
            = new AtomicReferenceArray<String>(names); 
  
        // print the length 
        int length = ref.length(); 
        System.out.println( 
            "length of AtomicReferenceArray = "
            + length); 
    } 
}
輸出:
length of AtomicReferenceArray = 3

參考文獻: https://docs.oracle.com/javase/10/docs/api/java/util/concurrent/atomic/AtomicReferenceArray.html#length()



相關用法


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