LinkedBlockingDeque contains() method in Java Last Updated : 14 Sep, 2018 Comments Improve Suggest changes Like Article Like Report 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 // 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 // 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) Comment More infoAdvertise with us Next Article LinkedBlockingDeque contains() method in Java G gopaldave Follow Improve Article Tags : Misc Java Java-Collections Java - util package Java-Functions Java-LinkedBlockingDeque +2 More Practice Tags : JavaJava-CollectionsMisc Similar Reads LinkedBlockingDeque offer() method in Java The offer(E e) method of LinkedBlockingDeque inserts the element passed in the parameter to the end of the Deque. If the container's capacity has exceeded, then it does not returns an exception as in case of add() and addFirst() function. Syntax: public boolean offer(E e) Parameters: This method acc 2 min read LinkedBlockingDeque element() method in Java The element() method of LinkedBlockingDeque returns the element at the front the container. It does not deletes the element in the container. This method returns the head of the queue represented by this deque. Syntax: public void element() Parameters: This method does not accept any parameter. Retu 2 min read LinkedBlockingDeque addFirst() method in Java The addFirst(E e) method of LinkedBlockingDeque inserts the element passed in the parameter to the front of the Deque if there is space. If the LinkedBlockingDeque is capacity restricted and no space is left for insertion, it returns an IllegalStateException. Syntax: public void addFirst(E e) Parame 2 min read LinkedBlockingDeque pop() method in Java The pop() method of LinkedBlockingDeque pops an element from the stack represented by this deque. In other words, it removes and returns the first element of this deque. It returns null if the container is empty. Syntax: public E pop() Parameters: This method does not accept any parameters. Returns: 2 min read LinkedBlockingDeque getFirst() method in Java The getFirst() method of LinkedBlockingDeque returns the front most element in the Deque container. If the LinkedBlockingDeque is empty, then on function call it returns a NoSuchElementException. Syntax: public E getLast() Parameters: This method does not accept any parameters. Returns: This method 2 min read LinkedBlockingDeque clear() method in Java The clear() method of LinkedBlockingDeque erases all the elements that are present in the LinkedBlockingDeque container. The container becomes empty after the function is called. Syntax: public void clear() Parameters: This method does not accepts any parameters Returns: This method does not returns 2 min read LinkedBlockingDeque getLast() method in Java The getLast() method of LinkedBlockingDeque returns the last element in the Deque container. If the LinkedBlockingDeque is empty, then on function call it returns a NoSuchElementException. Syntax: public E getLast() Parameters: This method does not accept any parameters. Returns: This method returns 2 min read LinkedBlockingDeque descendingIterator() method in Java The descendingIterator() method of LinkedBlockingDeque returns an iterator over the elements in this deque in a reverse sequential order. The elements will be returned in order from last(tail) to first(head). The returned iterator is a "weakly consistent" iterator. Syntax: public Iterator descending 2 min read LinkedBlockingDeque peekFirst() method in Java The peekFirst() method of LinkedBlockingDeque returns the front element in the Deque container, but does not deletes it. It returns null if the container is empty. Syntax: public E peekFirst() Parameters: This method does not accept any parameters. Returns: This method returns front element in the D 2 min read LinkedBlockingDeque offerFirst() method in Java The offerFirst(E e) method of LinkedBlockingDeque inserts the element passed in the parameter at the front of the Deque container. If the container's capacity has exceeded, then it does not returns an exception as in case of add() and addFirst() function. Syntax: public boolean offerFirst(E e) Param 2 min read Like