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.
精彩评论