I just read Is there a no-duplicate List implementation out there? answer about a List, NOT Set, implementation that doesn’t allow duplicates. The accepted answer recommended the Collections15 SetUniqueList. Is there some equivalent — in Guava perhaps? (I searched the docs and couldn’t find) — in other libs or is there some other currently popular solution?
I just read Is there a no-duplicate List implementation out there? answer about a
Share
The stuff in the answer you linked seems quite adequate. I’d go with one of those solutions. Alternatively, you could simply extend class
ArrayListand override some of the methods that do a check against aHashSetprior to callingsuper.methodfor that same method. Simply add the Set as an instance field, use it for checking dupes and add/remove whatever items get added to/removed from the list.