w3resource

Java ArrayDeque Class: contains() Method

public boolean contains(Object o)

The contains() method is used to check if a given deque contains an specified element or not.

More formally, returns true if and only if this deque contains at least one element e such that o.equals(e).

Package: java.util

Java Platform: Java SE 8

Syntax:

contains(Object o)

Parameters:

Name Description
o object to be checked for containment in this deque

Return Value:

true if this deque contains the specified element

Return Value Type: boolean

Pictorial Presentation

Java ArrayDeque Class: contains() Method

Example: Java ArrayDeque Class: contains() Method

import java.util.ArrayDeque;
import java.util.Deque;

public class Main {
   public static void main(String[] args) {
    // ArrayList with Capacity 4
      ArrayDeque<String> StudentList = new ArrayDeque<String>(4);
      //Added 4 elements
       StudentList.add("David");
       StudentList.add("Tom");
       StudentList.add("Rohit");
       StudentList.add("Paul");
      
       System.out.println("Students in the list are : ");
       System.out.println(StudentList);
  
       System.out.print("Is list contains the student Tom?");
       System.out.println(StudentList.contains("Tom"));
       System.out.print("Is list contains the student Sudhir?");
       System.out.println(StudentList.contains("Sudhir"));
   }
}
 

Output:

Students in the list are : 
[David, Tom, Rohit, Paul]
Is list contains the student Tom?true
Is list contains the student Sudhir?false

Java Code Editor:

Previous: clone Method
Next: descendingIterator Method



Follow us on Facebook and Twitter for latest update.