Java Utility Library

Java ArrayDeque - isEmpty() Method



The java.util.ArrayDeque.isEmpty() method is used to check whether the deque is empty or not. It returns true if the size of the deque is zero, else returns false.

Syntax

public boolean isEmpty()

Parameters

No parameter is required.

Return Value

true if the deque is empty, else returns false.

Exception

NA

Example:

In the example below, the java.util.ArrayDeque.isEmpty() method is used to check whether the deque is empty or not.

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //creating an ArrayDeque
    ArrayDeque<Integer> MyDeque = new ArrayDeque<Integer>();

    //checking ArrayDeque
    System.out.println("Is MyDeque empty?: " + MyDeque.isEmpty());

    //populating ArrayDeque
    MyDeque.add(10);
    MyDeque.add(20);
    MyDeque.add(30);

    //checking ArrayDeque
    System.out.println("Is MyDeque empty?: " + MyDeque.isEmpty());
  }
}

The output of the above code will be:

Is MyDeque empty?: true
Is MyDeque empty?: false

❮ Java.util - ArrayDeque