Reputation: 849
I have a situation where I have need a data structure that I can add strings to. This data structure is very large.
The specific qualities I need it have are:
I've tried using an ArrayList but the delete operation is o(n) and for a linkedList the traverse or get() operation will be o(n).
What other options do I have?
Upvotes: 1
Views: 722
Reputation: 7871
LinkedHashSet might be of interest. It is effectively a HashSet but it also maintains a LinkedList to allow a predictable iteration order - and therefore can also be used as a FIFO queue, with the nice added benefit that it can't contain duplicate entries.
Because it is a HashSet too, searches (as opposed to scans) can be O(1) if they can match on equals()
You can have a look at this question and this too.
Upvotes: 0
Reputation: 31823
circular buffer - one thats implemented with an array under the hood.
Upvotes: 6