I have a data structure for which I am currently using an ArrayList
. I realized that in this structure I do not want any duplicates to be present. My first thought was to use some form of dialing, however order is also important. After doing a little searching and searching in Collections LinkedHashSet
, I found a LinkedHashSet
that almost does the job. Unfortunately, one of the main reasons for maintaining order is that I use the get(int index)
method of ArrayList for random access, and I see no way around this.
More concise - I need a set that keeps order and allows random access. None of the classes that I have yet to examine provide this functionality. Does anyone know a class that offers this, or should I do it myself? If this is the last case, are there any pitfalls in creating such a structure that people know about?
(Alternatively, a quick and easy way to check and remove duplicates from an ArrayList or similar structure will suffice)
EDIT: for clarity, this is the order in which items are added to the list, which is important, not how they are compared to each other.
James source share