Is there a list type in java that stores objects in ascending order and not adds if this object is previously added. I know java maps can do that but I wonder if there is a list type that does what I want. Otherwise I have to override contains, equalsTo and add methods,right?
Advertisement
Answer
So you need a list containing only unique elements? Two options:
java.util.LinkedHashSet
– preserves the order of insertion, has the set semantics- from commons-collections
SetUniqueList
– allows list operations likeget(..)
andset(..)
- from commons-collections
ListOrderedSet