我的代码如下:
private LinkedBlockingQueue<TrackedOperation> operations = new LinkedBlockingQueue<TrackedOperation>(10000);
Iterator<TrackedOperation> it = operations.iterator();
while (it.hasNext()) {
TrackedOperation op = operations.remove();
...
}
我的问题是:
迭代器是否总是指向队列的头部,这是预期的行为吗?
如果我没有道理,那么我的问题是迭代器的行为是什么?我的操作队列和迭代器与上面的代码一致吗?
最佳答案
这是我所做的,
while (!linkedBlockingQueue.isEmpty()) {
linkedBlockingQueue.remove(); //do what you want to with it
}
关于java - 迭代 linkedBlockingQueue 并同时删除元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21292548/