开发者

Collection Queue

If I wanted to make a custom implementation of a Queue is correct to say that I can choose whatever order I want (not FIFO) but I must always respect the fact that the element to remove is that positioned as "hea开发者_StackOverflow中文版d"?

but for insertion operation I'm not obliged to put the element to the tail (like into FIFO)?


You are correct. The javadoc clearly states this:

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.


You are correct.

The Queue documentation even states this explicitly (emphasis mine):

Queues typically, but do not necessarily, order elements in a FIFO (first-in-first-out) manner. [...] Whatever the ordering used, the head of the queue is that element which would be removed by a call to remove() or poll().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜