How do a stack and a queue differ, and why use ArrayDeque in Java?
Short answer
A stack is last in, first out (LIFO), a queue is first in, first out (FIFO). In Java use ArrayDeque for both.
3 points to say:
- Stack: undo, DFS, bracket checking.
- Queue: BFS, job queues.
- Don't use
StackorLinkedList.
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.