An Deque interface.
ArrayDequecan be used as both a stack and a queue.Nullelements are prohibited.
isEmpty methodThe isEmpty method can be used to check if the ArrayDeque object has no elements.
public boolean isEmpty()
This method does not take any arguments.
This method returns true if the arrayDeque object has no elements. Otherwise, it returns false.
The code below demonstrates how to use the isEmpty method.
import java.util.ArrayDeque;class IsEmpty{public static void main( String args[] ) {ArrayDeque<String> arrayDeque = new ArrayDeque<>();System.out.println("the arrayDeque is : " + arrayDeque);System.out.println("Check if the arrayDeque is empty : " + arrayDeque.isEmpty());arrayDeque.add("1");System.out.println("\nthe arrayDeque is : " + arrayDeque);System.out.println("Check if the arrayDeque is empty : " + arrayDeque.isEmpty());}}
In the code above:
In line 1, we imported the ArrayDeque class.
In line 4, we created an ArrayDeque object with the name arrayDeque. This object doesn’t have any elements in it.
In line 6, we called the isEmpty method on the arrayDeque object. This method will return true because the arrayDeque object is empty.
In line 8, we used the add() method of the arrayDeque object to add one element ("1") to arrayDeque.
In line 10, we called the isEmpty method on the arrayDeque object. This method will return false because the arrayDeque object contains one element.