java - 收集队列

标签 java collections queue

如果我想自定义队列的实现,正确的是 说我可以选择我想要的任何顺序(不是 FIFO),但我必须始终 尊重要删除的元素定位为“head”的事实吗?

但对于插入操作,我没有义务将元素放在尾部(例如放入 FIFO 中)?

最佳答案

你是对的。 javadoc明确指出这一点:

Queues typically, but do not necessarily, order elements in a FIFO (first-in-first-out) manner. Among the exceptions are priority queues, which order elements according to a supplied comparator, or the elements' natural ordering, and LIFO queues (or stacks) which order the elements LIFO (last-in-first-out). Whatever the ordering used, the head of the queue is that element which would be removed by a call to remove() or poll(). In a FIFO queue, all new elements are inserted at the tail of the queue. Other kinds of queues may use different placement rules. Every Queue implementation must specify its ordering properties.

关于java - 收集队列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3522424/

相关文章:

java - Gson 不会将值写入使用 IntanceCreator 创建的对象

collections - 是否可以收集迭代器以向后填充集合?

ios - Swift语言的队列实现

java - 为什么我的迭代器 foreach 循环永远不会进入/执行?

java - Canvas 对象必须与之前由 lockCanvas 返回的实例相同

java - 关于 Intellij IDEA 与 scala 的问题

Java LinkedList 问题——如何删除满足特定条件的项

java - 使用 spring 表达式语言 (SpEL) 更新集合中的属性

java - 使用Java中的集合类进行排序不起作用

C# 节流 For 循环