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

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

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

Java .util.concurrent.ConcurrentLinkedDeque.isEmpty()是Java中的一个内置函数,用于检查双端队列是否包含元素。

句法:

public boolean isEmpty()

参数:该函数不接受任何参数。

返回:此方法返回一个布尔值,说明此双端队列是否为空。

下面的程序说明了 ConcurrentLinkedDeque.isEmpty() 方法:

示例:1

// Java Program Demonstrate
// isEmpty() method of ConcurrentLinkedDeque
  
import java.util.concurrent.*;
  
class ConcurrentLinkedDequeDemo {
    public static void main(String[] args)
    {
        ConcurrentLinkedDeque cld
            = new ConcurrentLinkedDeque();
  
        // Displaying the existing LinkedDeque
        System.out.println("ConcurrentLinkedDeque: "
                           + cld);
  
        // Check if the queue is empty
        // using isEmpty() method
        System.out.println("Is deque empty: "
                           + cld.isEmpty());
    }
}
输出:
ConcurrentLinkedDeque: []
Is deque empty: true

示例:2

// Java Program Demonstrate
// isEmpty() method of ConcurrentLinkedDeque
  
import java.util.concurrent.*;
  
class ConcurrentLinkedDequeDemo {
    public static void main(String[] args)
    {
        ConcurrentLinkedDeque cld
            = new ConcurrentLinkedDeque();
  
        cld.add("GFG");
        cld.add("Gfg");
        cld.add("GeeksforGeeks");
        cld.add("Geeks");
  
        // Displaying the existing LinkedDeque
        System.out.println("ConcurrentLinkedDeque: "
                           + cld);
  
        // Check if the queue is empty
        // using isEmpty() method
        System.out.println("Is deque empty: "
                           + cld.isEmpty());
    }
}
输出:
ConcurrentLinkedDeque: [GFG, Gfg, GeeksforGeeks, Geeks]
Is deque empty: false