开发者

ArrayDeque interface equivalent method with Queue interface

开发者 https://www.devze.com 2022-12-31 02:20 出处:网络
I know that ArrayDeque offers both ends of processing 开发者_运维百科(head and tail) but what i don\'t understand why the method offerlast() is equivalent to offer() method of Queue interface. Why not

I know that ArrayDeque offers both ends of processing 开发者_运维百科(head and tail) but what i don't understand why the method offerlast() is equivalent to offer() method of Queue interface. Why not offerfirst()? Pleae advice. Thanks


By convention, elements are inserted into a queue at the tail of the queue (after the last element) and retrieved from the head of a queue (the first element). Hence, offer is offerLast and poll is pollFirst.


Part of it is the structure of the Collections framework. The ArrayDeque class has both methods because in the implementation of ArrayDeque, they allow both adding to the front and end while other Deque implementation might not so they created the other methods to be more specific when using them if need be.

0

精彩评论

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