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


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<String> cld 
            = new ConcurrentLinkedDeque<String>(); 
  
        // 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<String> cld 
            = new ConcurrentLinkedDeque<String>(); 
  
        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


相關用法


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