Java LinkedBlockingDeque add() method21 Mar 2025 | 2 min read The add() method of LinkedBlockingDeque class inserts the specified element at the tail of this LinkedBlockingDeque. The add() method overrides the add in class AbstractQueue<E> Syntax:Parameters:e- It is the element to add Specified By:The add() method of ConcurrentLinkedQueue class is specified by:
Return Value:The add() method returns a Boolean value true, if the specified element is not null. 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: After adding 1 to the deque : [1] After adding 2 to the deque : [1, 2] After adding 3 to the deque : [1, 2, 3] After adding 4 to the deque : [1, 2, 3, 4] After adding 5 to the deque : [1, 2, 3, 4, 5] Example 2Output: 1. Name = Himanshu 2. Name = Jyoti 3. Name = Rahul Example 3Output: Deque : 71 8 18 19 Max number = 71 Min number = 8 Example 4Output: Exception in thread "main" java.lang.NullPointerException at java.util.concurrent.LinkedBlockingDeque.offerLast(LinkedBlockingDeque.java:357) at java.util.concurrent.LinkedBlockingDeque.addLast(LinkedBlockingDeque.java:334) at java.util.concurrent.LinkedBlockingDeque.add(LinkedBlockingDeque.java:633) at com.javaTpoint.LinkedBlockingDequeAddExample4.main(LinkedBlockingDequeAddExample4.java:11) Next TopicJava LinkedBlockingDeque |
Java LinkedBlockingDeque method The method of LinkedBlockingDeque class returns an iterator across the elements of this deque in the appropriate order. The elements returned will be in the order from head to tail. Syntax: public Iterator<E> Parameters: NA Specified By: The method of LinkedBlockingDeque class is specified by: ...
3 min read
Java LinkedBlockingDeque Method The method of LinkedBlockingDeque class adds the defined element at the tail of this deque. Syntax: public boolean offer(E e) public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException Parameters: e - It is the element to be added. timeout - It is the time till...
4 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 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 first element of this deque, and also removes it. The result returned by method is similar to that returned by Deque.removeFirst(). Syntax: public E Parameters: NA Specified By: The method of LinkedBlockingDeque class is specified by ...
2 min read
Java LinkedBlockingDeque Method The offerFirst () method of LinkedBlockingDeque class adds the defined elements at the front of this deque. Syntax: public boolean offerFirst(E e) public boolean offerFirst(E e, long timeout, TimeUnit unit) throws InterruptedException Parameters: e - It is the element to be added. timeout - It is the time...
3 min read
Java LinkedBlockingDeque method The method of LinkedBlockingDeque class returns the first 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 first element of...
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 returns an iterator over the elements of this queue. The elements are returned in the reverse sequential order. Syntax: public Iterator<E> Parameters: NA Specified By: The method of LinkedBlockingDeque class is specified by method of interface Deque<E>. Return Value: The ...
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