Java ConcurrentLinkedQueue remove() 方法

2024年10月21日 | 2 分钟阅读

如果队列中存在指定的元素,ConcurrentLinkedQueue 类的 remove() 方法会从队列中移除该元素。

语法

参数

参数 'o' 是要从队列中删除的元素(如果存在)。

指定者:

ConcurrentLinkedQueue 类的 remove() 方法由以下接口指定:

  • Collection<E> 接口中的 remove。

覆盖

ConcurrentLinkedQueue 类的 remove() 方法重写了:

  • AbstractCollection<E> 类中的 remove。

返回值

remove() 方法返回对应于此对象 'o' 的布尔值。

  • 如果元素存在于队列中,并且队列因该队列的更改而发生改变,则返回 true。
  • 否则,返回 false。

示例 1

输出

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

示例 2

输出

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

示例 3

输出

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