Java Deque contains() Method Tutorial

In this section we will learn what the Deque contains() method is and how to use it in Java.

What is Java Deque contains() Method?

The Java Deque contains() method is used to see if the target Deque object contained a specific element or not.

Java contains() Method Syntax:

boolean contains(Object o)

contains() Method Parameters:

The method takes one argument and that is the element we want to search for in a Deque object.

contains() Method Return Value:

The return value of this method is of type boolean.

If the target Deque object had the specified element, then the result of calling this method becomes true. Otherwise the value false will return instead.

contains() Method Exceptions:

The method does not throw an exception.

Example: using Deque contains() method

import java.util.ArrayDeque;
import java.util.Deque; 
class Main{
    public static void main(String[] args) {
        Deque<Integer> dq = new ArrayDeque<>();
        dq.add(1);
        dq.add(2);
        dq.add(3);
        dq.add(0);
        dq.add(10);

        System.out.println(dq.contains(10));
        System.out.println(dq.contains(3));
            
    }
}

Output:

true

true
Facebook
Twitter
Pinterest
LinkedIn

Top Technologies