gpt4 book ai didi

Java ConcurrentLinkedQueue 迭代元素顺序?

转载 作者:行者123 更新时间:2023-11-30 03:22:45 25 4
gpt4 key购买 nike

当前正在 for 循环中处理的元素是队列的头部吗?

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

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

或者这里使用 users.remove(u) 更好?

最佳答案

是的,ConcurrentLinkedQueue<E> 是正确的因为它按照 FIFO 顺序对元素进行排序。

来自docs :

This queue orders elements FIFO (first-in-first-out). 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.

关于Java ConcurrentLinkedQueue 迭代元素顺序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30962928/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com