LinkedBlockingDeque put() method in Java Last Updated : 17 Sep, 2018 Comments Improve Suggest changes Like Article Like Report The put(E e) method of LinkedBlockingDeque inserts the specified element into the queue represented by this deque (in other words, at the tail of this deque). If the Deque is capacity restricted, then it will wait for the space to become available. Syntax: public void put(E e) Parameters: This method accepts a mandatory parameter e which is the element to be inserted at the end of the LinkedBlockingDeque. Returns: This method does not return anything. Exceptions: The program throws two exceptions as shown below: NullPointerException - if the specified element is null InterruptedException - if interrupted while waiting Below programs illustrate put() method of LinkedBlockingDeque: Program 1: Java // Java Program Demonstrate put() // method of LinkedBlockingDeque import java.util.concurrent.LinkedBlockingDeque; import java.util.*; public class GFG { public static void main(String[] args) throws InterruptedException { // create object of LinkedBlockingDeque LinkedBlockingDeque<Integer> LBD = new LinkedBlockingDeque<Integer>(); // Add numbers to end of LinkedBlockingDeque LBD.put(7855642); LBD.put(35658786); LBD.put(5278367); LBD.put(74381793); // print Dequeue System.out.println("Linked Blocking Deque: " + LBD); } } Output: Linked Blocking Deque: [7855642, 35658786, 5278367, 74381793] Program 2: Java // Java Program Demonstrate put() // method of LinkedBlockingDeque // throwing NullPointerException import java.util.concurrent.LinkedBlockingDeque; import java.util.*; public class GFG { public static void main(String[] args) throws InterruptedException { // create object of LinkedBlockingDeque LinkedBlockingDeque<Integer> LBD = new LinkedBlockingDeque<Integer>(); // Add numbers to end of LinkedBlockingDeque LBD.put(7855642); LBD.put(35658786); LBD.put(5278367); // throws an exception LBD.put(null); // print Dequeue System.out.println("Linked Blocking Deque: " + LBD); } } Output: Exception in thread "main" java.lang.NullPointerException at java.util.concurrent.LinkedBlockingDeque.putLast(LinkedBlockingDeque.java:390) at java.util.concurrent.LinkedBlockingDeque.put(LinkedBlockingDeque.java:649) at GFG.main(GFG.java:22) Program 3: Java // Java Program Demonstrate put() // method of LinkedBlockingDeque // when capacity exceeded import java.util.concurrent.LinkedBlockingDeque; import java.util.*; public class GFG { public static void main(String[] args) throws InterruptedException { // create object of LinkedBlockingDeque LinkedBlockingDeque<Integer> LBD = new LinkedBlockingDeque<Integer>(3); // Add numbers to end of LinkedBlockingDeque LBD.put(7855642); LBD.put(35658786); LBD.put(5278367); // throws an exception LBD.put(4356789); // print Dequeue System.out.println("Linked Blocking Deque: " + LBD); } } Output: Runtime Errors: Max real time limit exceeded due to either by heavy load on server or by using sleep function Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/LinkedBlockingDeque.html#put-E- Comment More infoAdvertise with us Next Article LinkedBlockingDeque put() method in Java 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 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 LinkedBlockingDeque push() method in Java The push(E e) method of LinkedBlockingDeque pushes an element onto the stack represented by this deque. It 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 Ille 2 min read LinkedBlockingDeque peek() method in Java The peek() method of LinkedBlockingDeque returns the front element in the Deque container. It returns null if the container is empty. Syntax: public E peek() Parameters: This method does not accept any parameters. Returns: This method returns front element in the Deque container if the container is 2 min read LinkedBlockingDeque poll() method in Java The poll() method of LinkedBlockingDeque returns the front element in the Deque container and deletes it. It returns null if the container is empty. Syntax: public E poll() Parameters: This method does not accept any parameters. Returns: This method returns front element of the Deque container if th 2 min read 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 mandato 2 min read LinkedBlockingDeque offerLast() method in Java The offerLast(E e) method of LinkedBlockingDeque inserts the element passed in the parameter at the end of the Deque container. If the container's capacity has exceeded, then it does not returns an exception as in case of add() and addLast() function. Syntax: public boolean offerLast(E e) Parameters 2 min read LinkedBlockingDeque pollLast() method in Java The pollLast() method of LinkedBlockingDeque returns the last element in the Deque container, and deletes it. It returns null if the container is empty. Syntax: public E pollLast() Parameters: This method does not accept any parameters. Returns: This method returns last element in the Deque containe 2 min read LinkedBlockingDeque pollFirst() method in Java The pollFirst() method of LinkedBlockingDeque returns the front element in the Deque container, and deletes it. It returns null if the container is empty. Syntax: public E pollFirst() Parameters: This method does not accept any parameters. Returns: This method returns front element in the Deque cont 2 min read Like