Java中的Java.util.ArrayDeque.isEmpty()方法用於檢查和驗證ArrayDeque是否為空。如果雙端隊列為空,則返回True,否則返回False。
用法:
Array_Deque.isEmpty()
參數:該方法不帶任何參數。
返回值:如果雙端隊列為空,則該函數返回True,否則返回False。
下麵的程序演示了Java.util.ArrayDeque.isEmpty()方法:
示例1:
// Java code to illustrate isEmpty()
import java.util.*;
public class ArrayDequeDemo {
public static void main(String args[])
{
// Creating an empty ArrayDeque
Deque<String> de_que = new ArrayDeque<String>();
// 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
示例2:
// Java code to illustrate isEmpty()
import java.util.*;
public class ArrayDequeDemo {
public static void main(String args[])
{
// Creating an empty ArrayDeque
Deque<Integer> de_que = new ArrayDeque<Integer>();
// 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
相關用法
- Java ArrayDeque contains()用法及代碼示例
- Java ArrayDeque add()用法及代碼示例
- Java ArrayDeque pop()用法及代碼示例
- Java ArrayDeque peekFirst()用法及代碼示例
- Java ArrayDeque peek()用法及代碼示例
- Java ArrayDeque pollLast()用法及代碼示例
- Java ArrayDeque peekLast()用法及代碼示例
- Java ArrayDeque pollFirst()用法及代碼示例
- Java ArrayDeque removeLastOccurrence()用法及代碼示例
- Java ArrayDeque removeFirstOccurrence()用法及代碼示例
- Java ArrayDeque removeFirst()用法及代碼示例
- Java ArrayDeque removeLast()用法及代碼示例
- Java ArrayDeque remove()用法及代碼示例
- Java ArrayDeque iterator()用法及代碼示例
- Java ArrayDeque descendingIterator()用法及代碼示例
注:本文由純淨天空篩選整理自Chinmoy Lenka大神的英文原創作品 ArrayDeque isEmpty() Method in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。