LinkedBlockingDeque putLast() method in Java Last Updated : 17 Sep, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report The putLast(E e) method of LinkedBlockingDeque inserts the specified element into the queue represented by this deque (in other words, at the tail/end of this deque). If the Deque is capacity restricted, then it will wait for the space to become available. Syntax: public void putLast(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 putLast() method of LinkedBlockingDeque: Program 1: Java // Java Program Demonstrate putLast() // 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.putLast(7855642); LBD.putLast(35658786); LBD.putLast(5278367); LBD.putLast(74381793); // print Dequeue System.out.println("Linked Blocking Deque: " + LBD); } } Output: Linked Blocking Deque: [7855642, 35658786, 5278367, 74381793] Program 2: Java // Java Program Demonstrate putLast() // 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.putLast(7855642); LBD.putLast(35658786); LBD.putLast(5278367); // throws an exception LBD.putLast(null); // print Dequeue System.out.println("Linked Blocking Deque: " + LBD); } } Output: Runtime Errors: Exception in thread "main" java.lang.NullPointerException at java.util.concurrent.LinkedBlockingDeque.putLast(LinkedBlockingDeque.java:390) at GFG.main(GFG.java:23) Program 3: Java // Java Program Demonstrate putLast() // 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.putLast(7855642); LBD.putLast(35658786); LBD.putLast(5278367); // throws an exception LBD.putLast(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#putLast-E- Comment More infoAdvertise with us Next Article LinkedBlockingDeque remove() 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 removeLast() method in Java The removeLast() method of LinkedBlockingDeque returns and removes the element at tail of the Deque container. The method throws an NoSuchElementException if the Deque container is empty. Syntax: public E removeLast() Parameters: This method does not accepts any parameter. Returns: This method retur 2 min read LinkedBlockingDeque remove() method in Java The remove() method of LinkedBlockingDeque removes the head of the Deque container. The method throws a NoSuchElementException if the Deque container is empty. Syntax: public E remove() Parameters: This method does not accepts any parameter. Returns: This method does not returns anything. Exception: 2 min read LinkedBlockingDeque put() method in Java 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 metho 2 min read LinkedBlockingDeque putFirst() method in Java The putFirst(E e) method of LinkedBlockingDeque inserts the specified element at the front of the queue represented by this deque. If the Deque is capacity restricted, then it will wait for the space to become available. Syntax: public void putFirst(E e) Parameters: This method accepts a mandatory p 2 min read LinkedBlockingDeque removeFirst() method in Java The removeFirst() method of LinkedBlockingDeque returns and removes the first element of the Deque container from it. The method throws an NoSuchElementException if the Deque container is empty. Syntax: public E removeFirst() Returns: This method returns the head of the Deque container, which is the 2 min read LinkedBlockingDeque remainingCapacity() method in Java The remainingCapacity() method of LinkedBlockingDeque returns the number of additional elements that this deque can ideally (in the absence of memory or resource constraints) accept without blocking. remainingCapacity() = final_size() - current_size() Syntax: public int remainingCapacity() Parameter 2 min read LinkedBlockingDeque size() method in Java The size() method of LinkedBlockingDeque returns the current size of the Deque container. On calling the function the number of elements in the Deque container is returned. If the container is capacity restricted, then also it returns the number of elements which are present in the container at the 2 min read LinkedBlockingDeque spliterator() method in Java The spliterator() method of LinkedBlockingDeque returns a Spliterator on the elements of LinkedBlockingDeque. The returned iterator is weakly consistent. Spliterator can be used with Streams in Java 8. Spliterator can traverse elements individually and in bulk too. Syntax: public Spliterator spliter 2 min read LinkedBlockingDeque removeFirstOccurrence() method in Java The removeFirstOccurrence() method of LinkedBlockingDeque removes the first occurrence of the specified element from this deque. If the deque does not contain the element, it remains unchanged. It returns true if this deque contained the specified element, else it returns false. Syntax: public boole 2 min read LinkedBlockingDeque takeLast() method in Java The takeLast() method of LinkedBlockingDeque returns and removes the tail of the Deque container from it. The method throws an InterruptedException if it is interrupted while waiting. Syntax: public E takeLast() Returns: This method returns the tail(last element) of the Deque container. Exception: T 2 min read Like