This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

List and Set in one

 
Ronwaldo Cruz
Ranch Hand
Posts: 69
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

What do you usually use when you need a collection that is unique (like a Set) but has indexes (like a List)?
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe write a subclass of ArrayList that enforces the uniqueness of elements. There are probably ready-made classes like that out there.
 
Fahd Shariff
Ranch Hand
Posts: 38
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a LinkedHashSet
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fahd Shariff wrote:Use a LinkedHashSet

While LinkedHashSet will retain the iteration order, it is not indexable. That would have to be added.

I'd still go with Ulf's approach as it's easier to add uniqueness to a List than index-ability to a Set.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic