yapkm01
yapkm01

Reputation: 3773

ArrayDeque interface equivalent method with Queue interface

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

Upvotes: 0

Views: 195

Answers (2)

user147373
user147373

Reputation:

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.

Upvotes: 0

Seun Osewa
Seun Osewa

Reputation: 5033

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.

Upvotes: 2

Related Questions