📜  Java中的 ArrayDeque isEmpty() 方法

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

Java中的 ArrayDeque isEmpty() 方法

Java中的 .util.ArrayDeque.isEmpty() 方法用于检查和验证Java是否为空。如果双端队列为空,则返回 True,否则返回 False。

句法:

Array_Deque.isEmpty()

参数:该方法不带任何参数。

返回值:如果双端队列为空,则该函数返回 True,否则返回 False。

下面的程序说明了Java.util.ArrayDeque.isEmpty() 方法:

方案一:

// Java code to illustrate isEmpty()
import java.util.*;
  
public class ArrayDequeDemo {
    public static void main(String args[])
    {
        // Creating an empty ArrayDeque
        Deque de_que = new ArrayDeque();
  
        // Use add() method to add elements into the Deque
        de_que.add("Welcome");
        de_que.add("To");
        de_que.add("Geeks");
        de_que.add("4");
        de_que.add("Geeks");
  
        // Displaying the ArrayDeque
        System.out.println("ArrayDeque: " + de_que);
  
        // Verifying if the Deque is empty or not
        System.out.println("The Deque is empty? " + 
                                    de_que.isEmpty());
  
        // Clearing the deque
        de_que.clear();
  
        // Verifying if the Deque is empty or not
        System.out.println("The Deque is empty? " + 
                                    de_que.isEmpty());
    }
}
输出:
ArrayDeque: [Welcome, To, Geeks, 4, Geeks]
The Deque is empty? false
The Deque is empty? true

方案二:

// Java code to illustrate isEmpty()
import java.util.*;
  
public class ArrayDequeDemo {
    public static void main(String args[])
    {
        // Creating an empty ArrayDeque
        Deque de_que = new ArrayDeque();
  
        // Displaying the ArrayDeque
        System.out.println("ArrayDeque: " + de_que);
  
        // Verifying if the Deque is empty or not
        System.out.println("The Deque is empty? " + 
                                   de_que.isEmpty());
    }
}
输出:
ArrayDeque: []
The Deque is empty? true