![](/img/trans.png)
[英]How to get a element(at head) form ConcurrentLinkedQueue in java without removing the element
[英]Java ConcurrentLinkedQueue iteration element order?
當前是否正在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順序對元素進行排序。
從文檔 :
此隊列對元素FIFO(先進先出)進行排序。 隊列的開頭是已在隊列中停留最長時間的元素。 隊列的尾部是最短時間出現在隊列中的元素。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.