📌  相关文章
📜  Java中的 ConcurrentLinkedQueue isEmpty() 方法

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

Java中的 ConcurrentLinkedQueue isEmpty() 方法

ConcurrentLinkedQueueisEmpty()方法用于检查此队列是否为空。如果 ConcurrentLinkedQueue 包含零个元素,则返回 true 意味着 ConcurrentLinkedQueue 是否为空。

句法:

public boolean isEmpty()

返回:如果此 ConcurrentLinkedQueue 包含零个元素,则此方法返回true

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

示例 1:

// Java Program Demonstrate isEmpty()
// method of ConcurrentLinkedQueue
  
import java.util.concurrent.*;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create an ConcurrentLinkedQueue
        ConcurrentLinkedQueue
            queue = new ConcurrentLinkedQueue();
  
        // Add String to queue
        queue.add("Aman");
        queue.add("Amar");
        queue.add("Sanjeet");
        queue.add("Rabi");
  
        // Displaying the existing ConcurrentLinkedQueue
        System.out.println("ConcurrentLinkedQueue: " + queue);
  
        // check whether queue isEmpty or not
        boolean response1 = queue.isEmpty();
  
        // print after applying isEmpty method
        System.out.println("Is Queue empty: " + response1);
    }
}
输出:
ConcurrentLinkedQueue: [Aman, Amar, Sanjeet, Rabi]
Is Queue empty: false

示例 2:

// Java Program Demonstrate isEmpty()
// method of ConcurrentLinkedQueue
  
import java.util.concurrent.*;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create an ConcurrentLinkedQueue
        ConcurrentLinkedQueue
            queue = new ConcurrentLinkedQueue();
  
        // Displaying the existing ConcurrentLinkedQueue
        System.out.println("ConcurrentLinkedQueue: " + queue);
  
        // check whether queue is Empty
        boolean response1 = queue.isEmpty();
  
        // print after applying isEmpty method
        System.out.println("Is queue empty  : " + response1);
    }
}
输出:
ConcurrentLinkedQueue: []
Is queue empty  : true

参考: https: Java/util/concurrent/ConcurrentLinkedQueue.html#isEmpty–