I want to clarify some things here for the original poster, which others mentioned, but actually did not explicitly state. When you say you want a unique list, this is the very definition of an ordered set. Some other key differences between Set Interface and List include the fact that List allows you to specify an insertion index. So the question is, do you really need a list interface (i.e., for compatibility with a third-party library, etc.), Or can you redesign your software to use the Set interface? You should also consider what you do with the interface. Is it important to find items by their index? How many elements do you expect in your set? If you have many items, is it important to order?
If you really need a List that only has a unique constraint, there is an Apache Common Utils class org.apache.commons.collections.list.SetUniqueList that will provide you with a List interface and a unique constraint. Keep in mind that this violates the List interface. However, you will get better performance if you need to search the list by index. If you can deal with the Set interface, and you have a smaller data set, then LinkedHashSet can be a good way. It just depends on the design and intent of your software.
Again, there are certain advantages and disadvantages to each collection. Some fast inserts, but slow reads, some of them read fast, but slow inserts, etc. It makes sense to spend a lot of time building documentation to fully learn about the more subtle details of each class and interface.
Paul Connolly Dec 14 '14 at 18:23 2014-12-14 18:23
source share