ConcurrentLinkedQueue的isEmpty()方法用於檢查此隊列是否為空。如果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<String>
queue = new ConcurrentLinkedQueue<String>();
// 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<Integer>
queue = new ConcurrentLinkedQueue<Integer>();
// 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://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentLinkedQueue.html#isEmpty–
相關用法
- Java ConcurrentLinkedQueue contains()用法及代碼示例
- Java ConcurrentLinkedQueue add()用法及代碼示例
- Java ConcurrentLinkedQueue remove()用法及代碼示例
- Java ConcurrentLinkedQueue size()用法及代碼示例
- Java ConcurrentLinkedQueue offer()用法及代碼示例
- Java ConcurrentLinkedQueue spliterator()用法及代碼示例
- Java ConcurrentLinkedQueue peek()用法及代碼示例
- Java ConcurrentLinkedQueue iterator()用法及代碼示例
- Java ConcurrentLinkedQueue toArray()用法及代碼示例
- Java ConcurrentLinkedQueue addAll()用法及代碼示例
- Java ConcurrentLinkedQueue poll()用法及代碼示例
- Java CopyOnWriteArrayList isEmpty()用法及代碼示例
- Java LinkedHashSet isEmpty()用法及代碼示例
- Java HashMap isEmpty()用法及代碼示例
- Java AbstractSet isEmpty()用法及代碼示例
注:本文由純淨天空篩選整理自AmanSingh2210大神的英文原創作品 ConcurrentLinkedQueue isEmpty() method in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。