Queue vs Dequeue in java

Deque is short for “double ended queue”. With an ordinary queue, you add things to one end and take them from the other. With a double ended queue, you can add things to either end, and take them from either end. That makes it a bit more versatile; for example, you could use it as a stack if you wanted to.

In terms of efficiency, it really depends on the implementation. But generally speaking, you wouldn’t expect a deque to outperform a queue, because a (single ended) queue could be implemented in a way that doesn’t allow objects to be added or removed at the “wrong” end. Whereas any implementation of a deque would also work as an implementation of a queue.

Leave a Comment