Java LinkedBlockingDeque offerLast() Method

The offerLast() method of LinkedBlockingDeque class adds the defined elements at the end of this deque, only if the deque's capacity allows so.

Syntax:

Parameters:

e - It is the element to be added.

timeout - It is the time till the method has to wait before giving up, in units of unit.

unit - It is the TimeUnit that decides how to interpret the timeout parameter.

Specified By:

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

  1. offerLast() method in interface Deque<E>.
  2. offerLast() method in interface BlockingDeque<E>.

Return Value:

The offerLast() method returns true if the defined element is added to this deque, else returns false.

Throws:

The offerLast() method throws:

  1. NullPointerException - If the element defined holds null value.
  2. InterruptedException - If method call is interrupted during wait.

Example 1

Test it Now

Output:

[15, 16, 17, 18, 19, 20]
After inserting 21 at Last position
[15, 16, 17, 18, 19, 20, 21]

Example 2

Test it Now

Output:

1. Kapil
2. Payal
3. Diksha
4. Nishank
After adding string at last position :
1. Kapil
2. Payal
3. Diksha
4. Nishank
5. Manav





Latest Courses