Java ArrayBlockingQueue remove() Method

The remove() method of ArrayBlockingQueue class removes the specified element from the queue, if that element is present in the queue.

Syntax:

Parameters:

The parameter 'o' is passed which is removed from the queue, if the element is present.

Specified By:

The remove () method of ArrayBlockingQueue class is specified by:

  • remove in interface BlockingQueue<E>.
  • remove in interface Collection<E>.

Return Value:

The remove() method returns a Boolean value corresponding to this Object 'o':

  • It returns ture, if the element is present in the queue and the queue is changed as a result of this queue.
  • Else it returns false.

Example 1

Output:

Elements in queue : [12, 98, 122, 102, 112]
Remaining elements in queue : [12, 98, 112]

Example 2

Output:

Cake
Pulses
Sugar
Salt
Basmati Rice
Aata
New List : [Pulses, Sugar, Basmati Rice, Aata]