Java LinkedBlockingDeque add() method

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:

  1. add in interface BlockingDeque<E>
  2. add in interface BlockingQueue<E>
  3. add in interface Queue<E>.
  4. add in interface Collection<E>.
  5. add ininterface Deque<E>.

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 1

Test it Now

Output:

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 2

Test it Now

Output:

1. Name = Himanshu
2. Name = Jyoti
3. Name = Rahul

Example 3

Test it Now

Output:

Deque :
71
8
18
19
Max number = 71
Min number = 8

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 java.util.concurrent.LinkedBlockingDeque.add(LinkedBlockingDeque.java:633)
	at com.javaTpoint.LinkedBlockingDequeAddExample4.main(LinkedBlockingDequeAddExample4.java:11)





Latest Courses