简体   繁体   English

Java ConcurrentLinkedQueue迭代元素顺序?

[英]Java ConcurrentLinkedQueue iteration element order?

Is the element currently being processed in a for loop, the head of the queue? 当前是否正在for循环(队列的开头)中处理元素?

private Queue<User> users = new ConcurrentLinkedQueue<User>();

for(User u : users){
    users.remove(); // <- is this removing the currently iterated element?
}

Or is using users.remove(u) preferable here? 还是在这里最好使用users.remove(u)

Yes, that is correct for ConcurrentLinkedQueue<E> since it orders elements in FIFO order. 是的,这对ConcurrentLinkedQueue<E>是正确的,因为它以FIFO顺序对元素进行排序。

From the docs : 文档

This queue orders elements FIFO (first-in-first-out). 此队列对元素FIFO(先进先出)进行排序。 The head of the queue is that element that has been on the queue the longest time. 队列的开头是已在队列中停留最长时间的元素。 The tail of the queue is that element that has been on the queue the shortest time. 队列的尾部是最短时间出现在队列中的元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM