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

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

Java中的 AbstractSequentialList isEmpty() 方法及示例

Java中AbstractSequentialListisEmpty()方法用于检查这个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 arr
            = new LinkedList();
  
        // 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 arr
            = new LinkedList();
  
        // 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