Java LinkedBlockingDeque addFirst() method21 Mar 2025 | 2 min read The addFirst() method of LinkedBlockingDeque class inserts the specified element at the front of this LinkedBlockingDeque. This method throws IllegalStateException if the specified element is null. Syntax:Parameters:e- It is the element to add Specified By:The addFirst() method of ConcurrentLinkedQueue class is specified by :
Throws:NullPointerException: This exception will throw if the specified element e is null. IllegalStateException: This exception will throw if this deque is full. Example 1Output: [1, 2, 3, 4, 5] After inserting 10 at first position [10, 1, 2, 3, 4, 5] Example 2Output: 1. Disha 2. Tanmay 3. Prachi 4. Garvit After adding string : 1. Diya 2. Disha 3. Tanmay 4. Prachi 5. Garvit Example 3Output: Exception in thread "main" java.lang.IllegalStateException: Deque full at java.util.concurrent.LinkedBlockingDeque.addFirst(LinkedBlockingDeque.java:326) at com.javaTpoint.LinkedBlockingDequeAddFirstExample3.main (LinkedBlockingDequeAddFirstExample3.java:13) Next TopicLinkedblockingdeque add() |
Java LinkedBlockingDeque method The method of LinkedBlockingDeque class returns the head of the queue corresponding to this deque but does not withdraw it. The result returned by this method is similar to the one returned by getFirst() method. Syntax: public E Parameters: NA Specified By: The method of...
3 min read
Java LinkedBlockingDeque Method The method of LinkedBlockingDeque class retrieves the head of the queue corresponding to this deque, but doesn't remove it. The method returns null if this deque is empty. Syntax: public E Parameters: NA Specified By: The method of LinkedBlockingDeque class is specified by: method in...
3 min read
Java LinkedBlockingDeque Method The method of LinkedBlockingDeque class adds the defined elements at the end of this deque, only if the deque's capacity allows so. Syntax: public boolean offerLast(E e) public boolean offerLast(E e, long timeout, TimeUnit unit) throws InterruptedException Parameters: e - It is the element to be...
2 min read
Java LinkedBlockingDeque Method The method is used to check the presence of the specified element in the deque. If the element is present in the deque, then this method returns true otherwise it returns false. Syntax: public boolean contains(Object o) Parameters: o - this is the object that...
2 min read
Java LinkedBlockingDeque method The method of LinkedBlockingDeque class returns the last element of this deque but does not withdraw it. Syntax: public E Parameters: NA Specified By: The method of LinkedBlockingDeque class is specified by method in interface Deque<E>. Return Value: The method returns the last element of...
1 min read
Java LinkedBlockingDeque method The method of LinkedBlockingDeque class is used to add all the elements of the specified collection at the end of this deque. This method overrides in class AbstractQueue<E>. Syntax: public boolean addAll(Collection<? extends E> c Parameters: c- the elements to be added to this...
3 min read
Java LinkedBlockingDeque Method The method of LinkedBlockingDeque() class removes all the elements present in this queue and adds them to the provided collection. Syntax: public int drainTo(Collection<? super E> c) public int drainTo(Collection<? super E> c, int maxElements) Parameters: c - this is the collection to which elements are...
3 min read
Java LinkedBlockingDeque method The method of LinkedBlockingDeque class adds the specified elements at the end of this deque, without exceeding the capacity. Syntax: public void addLast(E e) Parameters: e - this is the element to be added. Specified By: The method of LinkedBlockingDeque class is specified by : in...
3 min read
Java LinkedBlockingDeque Method The method of LinkedBlockingDeque class retrieves the first element of this deque, and also removes it. The method returns null if this deque is empty. The pollFirst(long timeout, TimeUnit unit) method of LinkedBlockingDeque class retrieves the first element of this deque, awaiting...
2 min read
Java LinkedBlockingDeque method The method of LinkedBlockingDeque class automatically withdraws all the elements from this deque. The deque becomes empty, after calling this method. Syntax: public void Parameters: NA Specified By: The method of class LinkedBlockingDeque is specified by method in interface Collection<E>. Override: The method of class...
3 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India