In this shot, we will discuss how to use the Deque.isEmpty()
method in Java.
The Deque.isEmpty()
method is present in the Deque
interface inside the java.util
package.
Deque.isEmpty()
is used to check whether the deque is empty or not.
boolean isEmpty()
The Deque.isEmpty()
method doesn’t take any parameters.
The Deque.isEmpty()
method returns a boolean value:
True
: When the deque is empty.False
: When the deque is not empty.Let us look at the code snippet below.
import java.util.*;class Main{public static void main(String[] args){// Create the integer listDeque<Integer> d = new LinkedList<Integer>();// add elements in the listd.add(2);d.add(28);d.add(6);d.add(80);d.add(21);d.add(7);d.add(15);// check list isempty or notif(d.isEmpty())System.out.println("Deque is empty.");elseSystem.out.println("Deque is not empty.");}}
Main
class.main
function.Integer
type elements.Deque.add()
method to insert the elements in the deque.In this way, we can use the Deque.isEmpty()
method in Java.