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


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


Java中的AbstractSequentialList的isEmpty()方法用於檢查此AbstractSequentialList是否為空。它返回一個表示是否相同的布爾值。

用法:

public boolean isEmpty()

參數:此函數沒有參數。


返回:該方法返回一個布爾值,該值表明AbstractSequentialList的實例為空。

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

範例1:

// Java code to demonstrate the working of 
// isEmpty() 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); 
  
        // Check if AbstractSequentialList is empty 
        // using isEmpty() value 
        System.out.println("Is AbstractSequentialList empty? "
                           + arr.isEmpty()); 
    } 
}
輸出:
AbstractSequentialList:[1, 2, 3, 4]
Is AbstractSequentialList empty? false

範例2:

// Java code to demonstrate the working of 
// isEmpty() method in AbstractSequentialList 
  
import java.util.*; 
  
public class GFG { 
    public static void main(String[] args) 
    { 
        // creating an AbstractSequentialList 
        AbstractSequentialList<String> arr 
            = new LinkedList<String>(); 
  
        // print AbstractSequentialList 
        System.out.println("AbstractSequentialList:"
                           + arr); 
  
        // Check if AbstractSequentialList is empty 
        // using isEmpty() value 
        System.out.println("Is AbstractSequentialList empty? "
                           + arr.isEmpty()); 
    } 
}
輸出:
AbstractSequentialList:[]
Is AbstractSequentialList empty? true


相關用法


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