Java LinkedBlockingDeque offer() Method

The offer() method of LinkedBlockingDeque class adds the defined element at the tail of this deque.

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 offer() method of LinkedBlockingDeque class is specified by:

  1. offer() method in interface Queue<E>.
  2. offer() method in interface Deque<E>.
  3. offer() method in interface BlockingQueue<E>.
  4. offer() method in interface BlockingDeque<E>.

Return Value:

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

Throws:

The offer() 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:

Queue before using offer() : 
[567, 56, 5671, 5167]
Queue after using offer() : 
[567, 56, 5671, 5167, 5670]

Example 2

Test it Now

Output:

Albert
Christeena
Aviral
Pratik
Janak

Example 3

Test it Now

Output:

Harshit  Bhardwaj     15023022
Rahul  Verma          15023045
Deepanjali  Thakur    15023015
Raman  Mehta          14022056





Latest Courses