Collections · interview question
If you need a collection that supports quick insertion and removal of elements at both ends, but also provides indexed access, which would you choose?
Multiple choiceHardchapter-4-curatedpremiumcollectionschoosing-the-right-collection
Answer and explanation
Correct answer
C. LinkedList
Why
LinkedList can be used as a list and deque, allowing quick insertion and removal at both ends, as well as access by index, while ArrayDeque does not support indexing.
Test yourself on Collections
A free test with instant, explained results. No account needed.
More Collections questions
- Which Java collection should you use if you need to store elements with fast random access and allow duplicates?
- Which collection does not allow duplicate elements?
- Which Java collection would you choose if you need to maintain insertion order and allow duplicates?
- How would you explain a key advantage of using a HashMap over a TreeMap in an interview?
- You are tasked with designing a cache system in Java where both insertion order and fast access are crucial. Which…
- You need a collection for an in-memory product catalog where order matters and items must be unique. Which collection…