ArrayDeque vs Stack vs LinkedList Java | Fresher Interview
Fast recall
Quick revision
Core answer
Vector and is synchronized/slow) and `LinkedList` (which has poor cache locality and per-node memory overhead). ArrayDeque gives O(1) add/remove at both ends with contiguous-array speed - but it's not thread-safe and disallows null.Whether you know why ArrayDeque is preferred over Stack and LinkedList for stack/queue use
Defaulting to Stack or LinkedList out of habit, or assuming ArrayDeque is thread-safe
Cite Stack's synchronization/Vector inheritance and LinkedList's cache/memory cost as the reasons
Interview-ready guide
Interview answer
ArrayDeque is a double-ended queue backed by a resizable circular array, and it's the class I reach for whenever I need a stack or a queue in Java.
It gives O of one insertion and removal at both ends, so it works as a stack using push and pop, or as a queue using offer and poll. The reason it's preferred comes down to comparing it against the two classes people often use out of habit.
The legacy Stack class extends Vector, which means it's synchronized, so you pay locking overhead on every operation even in single-threaded code, and it inherits index-based access from Vector that breaks the clean stack abstraction. LinkedList can also act as a deque, but it allocates a separate node for every element, which scatters data across memory and gives poor cache locality, plus each node carries pointer overhead.
ArrayDeque, with its contiguous backing array, is faster in practice and uses less memory. There are two important caveats. First, ArrayDeque is not thread-safe, so if I need concurrent access I'd use something like ConcurrentLinkedDeque or LinkedBlockingDeque instead.
Second, ArrayDeque does not allow null elements; it throws a NullPointerException if you try to add null, because it uses null internally as a sentinel to mean absent. So the short version is: use ArrayDeque for stacks and queues, avoid the synchronized legacy Stack and the cache-unfriendly LinkedList, and remember it's neither thread-safe nor null-friendly.
ArrayDeque vs Stack vs LinkedList Java | Fresher Interview
Direct Answer
ArrayDeque is a resizable-array double-ended queue that's the preferred choice for both stacks and queues in Java. It beats the legacy Stack (which extends Vector and is synchronized/slow) and LinkedList (which has poor cache locality and per-node memory overhead). ArrayDeque gives O(1) add/remove at both ends with contiguous-array speed - but it's not thread-safe and disallows null.
Code Example
// As a STACK (LIFO)
Deque<Integer> stack = new ArrayDeque<>();
stack.push(1); stack.push(2);
System.out.println(stack.pop()); // 2
// As a QUEUE (FIFO)
Queue<Integer> queue = new ArrayDeque<>();
queue.offer(1); queue.offer(2);
System.out.println(queue.poll()); // 1
// Caveat: nulls are rejected
// stack.push(null); // throws NullPointerException
One class, both roles, all O(1) - no synchronization tax like Stack.
Common Mistakes & Pitfalls
- Defaulting to
Stack: synchronized +Vectorinheritance; useArrayDeque. LinkedListas a queue: works but slower (cache misses, pointer overhead).- Assuming thread safety:
ArrayDequeis not synchronized; useConcurrentLinkedDeque/LinkedBlockingDeque. - Storing null:
ArrayDequerejects null - it's used internally as a sentinel.
Check your understanding
Answer these without looking back at the article.
- What is a deque?
- When would you use a thread-safe queue?
- How does ArrayDeque resize internally?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.