SteelReed

Search

Search posts, questions…

Collections & DSAQuestion 4 / 25

Junior

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.

replace withpush / pop at headoffer tail, poll headjava.util.Stackextends VectorArrayDequecircular arrayStack LIFOundo, DFS, bracketsQueue FIFOBFS, jobs, buffer

3 points to say:

  1. Stack: undo, DFS, bracket checking.
  2. Queue: BFS, job queues.
  3. Don't use Stack or LinkedList.

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.