Wednesday, July 8, 2026
HomeLanguagesJavaLinkedBlockingDeque contains() method in Java

LinkedBlockingDeque contains() method in Java

The contains(Object o) method of LinkedBlockingDeque checks if the passed element in the parameter exists in the container or not. It returns true if the element exists in the container else it returns a false value.

Syntax:

public boolean contains(Object o)

Parameters: This method accepts a mandatory parameter o whose presence in the container is to be checked in the container.

Returns: This method returns true if the element is present, else it returns false.

Below programs illustrate contains() method of LinkedBlockingDeque:

Program 1:




// Java Program Demonstrate contains()
// method of LinkedBlockingDeque
  
import java.util.concurrent.LinkedBlockingDeque;
import java.util.*;
  
public class GFG {
    public static void main(String[] args)
        throws IllegalStateException
    {
  
        // create object of LinkedBlockingDeque
        LinkedBlockingDeque<Integer> LBD
            = new LinkedBlockingDeque<Integer>();
  
        // Add numbers to end of LinkedBlockingDeque
        LBD.add(10);
        LBD.add(20);
        LBD.add(30);
        LBD.add(40);
  
        // before removing print queue
        System.out.println("Linked Blocking Deque: " + LBD);
  
        // check for presence using function
        if (LBD.contains(10)) {
            System.out.println("Linked Blocking Deque contains 10");
        }
        else {
            System.out.println("Linked Blocking Deque does not contain 10");
        }
    }
}


Output:

Linked Blocking Deque: [10, 20, 30, 40]
Linked Blocking Deque contains 10

Program 2:




// Java Program Demonstrate contains()
// method of LinkedBlockingDeque
import java.util.concurrent.LinkedBlockingDeque;
import java.util.*;
  
public class GFG {
    public static void main(String[] args)
        throws IllegalStateException
    {
  
        // create object of LinkedBlockingDeque
        LinkedBlockingDeque<String> LBD
            = new LinkedBlockingDeque<String>();
  
        // Add numbers to end of LinkedBlockingDeque
        LBD.add("ab");
        LBD.add("cd");
        LBD.add("fg");
        LBD.add("xz");
  
        // before removing print queue
        System.out.println("Linked Blocking Deque: " + LBD);
  
        // check for presence using function
        if (LBD.contains("go")) {
            System.out.println("Linked Blocking Deque contains 'go'");
        }
        else {
            System.out.println("Linked Blocking Deque does not contain 'go'");
        }
    }
}


Output:

Linked Blocking Deque: [ab, cd, fg, xz]
Linked Blocking Deque does not contain 'go'

Reference: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/LinkedBlockingDeque.html#contains(java.lang.Object)

RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32519 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6900 POSTS0 COMMENTS
Nicole Veronica
12016 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12110 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7263 POSTS0 COMMENTS
Thapelo Manthata
6978 POSTS0 COMMENTS
Umr Jansen
6968 POSTS0 COMMENTS