☕ Java
Intermediate
What is the Deque interface in Java?
Answer
A Deque (Double-Ended Queue) supports adding and removing elements from both ends efficiently. It combines the functionality of both a Stack (LIFO) and a Queue (FIFO). The Deque interface provides methods for both ends: addFirst()/addLast(), removeFirst()/removeLast(), peekFirst()/peekLast(). Main implementations: ArrayDeque (resizable array, no null elements, faster than Stack and LinkedList for stack/queue use) and LinkedList (node-based). Java's Stack class is legacy and thread-synchronized — prefer ArrayDeque for stack and queue operations in single-threaded code.
More Java Questions
View all →- Intermediate What is the Java Collections Framework?
- Intermediate What is the difference between ArrayList and LinkedList?
- Intermediate What is HashMap in Java and how does it work internally?
- Intermediate What is the difference between HashMap and HashTable in Java?
- Intermediate What is the difference between HashMap and LinkedHashMap?