• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Collection that keeps order

 
Tom Henricksen
Ranch Hand
Posts: 136
Eclipse IDE jQuery Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which collection would you use if you want to guarantee the order of how they were put in. As in:



Then iterate over coming out B,C,A. I know ArrayList is wrong but just for example.
Thanks,
Tom
 
Svend Rost
Ranch Hand
Posts: 904
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about a class that implements the abstract class: java/util/AbstractSequentialList

http://java.sun.com/j2se/1.4.2/docs/api/java/util/AbstractSequentialList.html


Does that help?

/Svend Rost
 
Tom Henricksen
Ranch Hand
Posts: 136
Eclipse IDE jQuery Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Svend that did the trick! I owe you one...
Tom
 
jiju ka
Ranch Hand
Posts: 306
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the collection contains only unique elements, consider a set.

Treeset can be an option in that case.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know why you say "ArrayList is wrong", or why the interface "AbstractSequentialList" changes anything. A list, by definition, keeps its elements in a specified order. ArrayList does, LinkedList does, and so do all other Lists.

Did you have some specific problem with ArrayList that we can help you with?
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic