Java LinkedBlockingDeque addLast() method

The addLast() method of LinkedBlockingDeque class adds the specified elements at the end of this deque, without exceeding the capacity.

Syntax:

Parameters:

e - this is the element to be added.

Specified By:

The addLast() method of LinkedBlockingDeque class is specified by :

  • addLast() in interface BlockingDeque<E>.
  • addLast() in interface Deque<E>.

Throws:

The add() method throws:

NullPointerException - if the specified element e, is null.

IllegalStateException - if this deque is full

Example 1

Test it Now

Output:

[1, 2, 3, 4, 5]
After inserting 10 at Last position
[1, 2, 3, 4, 5, 10]

Example 2

Test it Now

Output:

1. Disha
2. Tanmay
3. Prachi
4. Garvit
After adding string at last position :
1. Disha
2. Tanmay
3. Prachi
4. Garvit
5. Diya

Example 3

Test it Now

Output:

Exception in thread "main" java.lang.IllegalStateException: Deque full
	at java.util.concurrent.LinkedBlockingDeque.addFirst(LinkedBlockingDeque.java:326)
	at com.javaTpoint.LinkedBlockingDequeAddLastExample3.main(LinkedBlockingDequeAddLastExample3.java:12)

Example 4

Test it Now

Output:

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 com.javaTpoint.LinkedBlockingDequeAddLastExample4.main(LinkedBlockingDequeAddLastExample4.java:11)
dr





Latest Courses