当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java LinkedBlockingDeque isEmpty()用法及代码示例


Java中LinkedBlockingDeque的isEmpty()方法用于检查此LinkedBlockingDeque是否为空。它返回一个表示是否相同的布尔值。

用法:

public boolean isEmpty()

参数:此方法不接受参数。


返回值:该方法返回一个布尔值,该值表明LinkedBlockingDeque的实例为空。

以下示例说明了LinkedBlockingDeque.isEmpty()方法:

示例1:

// Java Program Demonstrate isEmpty() 
// method of LinkedBlockingDeque 
  
import java.util.concurrent.LinkedBlockingDeque; 
import java.util.*; 
  
public class GFG { 
    public static void main(String[] args) 
        throws IllegalStateException 
    { 
  
        // create object of LinkedBlockingDeque 
        LinkedBlockingDeque<Integer> LBD 
            = new LinkedBlockingDeque<Integer>(); 
  
        // Add numbers to end of LinkedBlockingDeque 
        LBD.add(7855642); 
        LBD.add(35658786); 
        LBD.add(5278367); 
        LBD.add(74381793); 
  
        System.out.println("Linked Blocking Deque: " + LBD); 
  
        // using isEmpty() function 
        System.out.println("Is Linked Blocking Deque empty: "
                           + LBD.isEmpty()); 
    } 
}
输出:
Linked Blocking Deque: [7855642, 35658786, 5278367, 74381793]
Is Linked Blocking Deque empty: false

示例2:

// Java Program Demonstrate isEmpty() 
// method of LinkedBlockingDeque 
// when the list contains characters 
  
import java.util.concurrent.LinkedBlockingDeque; 
import java.util.*; 
  
public class GFG { 
    public static void main(String[] args) 
        throws IllegalStateException 
    { 
  
        // create object of LinkedBlockingDeque 
        LinkedBlockingDeque<String> LBD 
            = new LinkedBlockingDeque<String>(); 
  
        System.out.println("Linked Blocking Deque: " + LBD); 
  
        // using isEmpty() function 
        System.out.println("Is Linked Blocking Deque empty: "
                           + LBD.isEmpty()); 
    } 
}
输出:
Linked Blocking Deque: []
Is Linked Blocking Deque empty: true


相关用法


注:本文由纯净天空筛选整理自Code_r大神的英文原创作品 LinkedBlockingDeque isEmpty() method in Java with Example。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。