📜  Java中的 LinkedBlockingDeque isEmpty() 方法示例

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

Java中的 LinkedBlockingDeque isEmpty() 方法示例

Java中LinkedBlockingDequeisEmpty()方法用于检查这个LinkedBlockingDeque是否为空。它返回一个布尔值,说明相同。

句法:

public boolean isEmpty()

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

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

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

方案一:

// 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 LBD
            = new LinkedBlockingDeque();
  
        // 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

方案二:

// 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 LBD
            = new LinkedBlockingDeque();
  
        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