Home » Java ConcurrentLinkedQueue remove() Method

Java ConcurrentLinkedQueue remove() Method

by Online Tutorials Library

Java ConcurrentLinkedQueue remove() Method

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

Syntax:

Parameters:

The parameter ‘o’ is the element to be removed from the queue if it is present.

Specified By:

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

  • remove in interface Collection<E>.

Overrides:

The remove () method of ConcurrentLinkedQueue class overrides:

  • remove in class AbstractCollection<E>.

Return Value:

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

  • It returns true 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

Test it Now

Output:

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

Example 2

Test it Now

Output:

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

Example 3

Test it Now

Output:

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

You may also like