Java Interview Question
Use this basic question and answer to prepare for your next Java interview.
What Collection would you use to iterate with insertion order and also have
O(1) lookup time? Are there any drawbacks to using this Collection?
LinkedHashSet provides an average
O(1) lookup time and also maintains the entries in a doubly-linked list, which can be used to maintain insertion order. The only drawback in this case is that we cannot have duplicates in the Collection because it is a Set.