Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java : list that contains unique elements in order

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?

like image 554
meandbobbymcgee Avatar asked Sep 06 '25 17:09

meandbobbymcgee


1 Answers

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 like get(..) and set(..)
  • from commons-collections ListOrderedSet
like image 118
Bozho Avatar answered Sep 10 '25 11:09

Bozho