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


Java AbstractSequentialList size()用法及代碼示例


Java中的AbstractSequentialList的size()方法用於獲取AbstractSequentialList的實例的大小。它返回一個整數值,該值是此AbstractSequentialList實例的大小。

用法:

public int size()

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


返回:該方法返回一個整數值,該值是此AbstractSequentialList實例的大小。

以下示例說明了AbstractSequentialList.size()方法:

範例1:

// Java code to demonstrate the working of 
// size() method in AbstractSequentialList 
  
import java.util.*; 
  
public class GFG { 
    public static void main(String[] args) 
    { 
        // creating an AbstractSequentialList 
        AbstractSequentialList<Integer> arr 
            = new LinkedList<Integer>(); 
  
        // using add() to initialize values 
        // [1, 2, 3, 4] 
        arr.add(1); 
        arr.add(2); 
        arr.add(3); 
        arr.add(4); 
  
        // print AbstractSequentialList 
        System.out.println("AbstractSequentialList:"
                           + arr); 
  
        // Get the size 
        // using size() 
        System.out.println("Size:"
                           + arr.size()); 
    } 
}
輸出:
AbstractSequentialList:[1, 2, 3, 4]
Size:4

範例2:

// Java code to demonstrate the working of 
// size() method in AbstractSequentialList 
  
import java.util.*; 
  
public class GFG { 
    public static void main(String[] args) 
    { 
        // creating an AbstractSequentialList 
        AbstractSequentialList<String> arr 
            = new LinkedList<String>(); 
  
        // using add() to initialize values 
        // [Geeks, For, ForGeeks, GeeksForGeeks] 
        arr.add("Geeks"); 
        arr.add("For"); 
        arr.add("ForGeeks"); 
        arr.add("GeeksForGeeks"); 
  
        // print AbstractSequentialList 
        System.out.println("AbstractSequentialList:"
                           + arr); 
  
        // Get the size 
        // using size() 
        System.out.println("Size:"
                           + arr.size()); 
    } 
}
輸出:
AbstractSequentialList:[Geeks, For, ForGeeks, GeeksForGeeks]
Size:4


相關用法


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