Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

contains
java
communitycreator

What is the ConcurrentLinkedDeque.contains() method in Java?

Programming Bytes

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The ConcurrentLinkedDeque is a thread-safe unbounded deque. Null is not permitted as an element. We can use the ConcurrentLinkedDeque when multiple threads are sharing a single deque.

The contains method of the ConcurrentLinkedDeque class can be used to check if an element is present in the deque.

Syntax

public boolean contains(Object o)

Parameters

This method takes the element to be checked for availability as an argument.

Return value

This method returns true if the element is present in the deque. Otherwise, false will be returned.

Code

The code below demonstrates how to use the contains method.

import java.util.concurrent.ConcurrentLinkedDeque;
class Contains {
public static void main( String args[] ) {
ConcurrentLinkedDeque<String> deque = new ConcurrentLinkedDeque<>();
deque.add("1");
deque.add("2");
deque.add("3");
System.out.println("The deque is " + deque);
System.out.println("deque.contains(1) - " + deque.contains("1"));
System.out.println("deque.contains(4) - " + deque.contains("4"));
}
}

In the above code,

  • We imported the ConcurrentLinkedDeque from the java.util.concurrent package.

  • We created an object for the ConcurrentLinkedDeque class with the name deque.

  • We added three elements to the deque object.

  • We used the contains method to check if an element is present in deque.

    • For the argument 1, the contains method returns true.
    • For the argument 4, the contains method returns false.

RELATED TAGS

contains
java
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring