wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Collection that keeps order Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Collection that keeps order" Watch "Collection that keeps order" New topic
Author

Collection that keeps order

Tom Henricksen
Ranch Hand

Joined: Mar 23, 2004
Posts: 136

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

Joined: Oct 23, 2002
Posts: 904
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

Joined: Mar 23, 2004
Posts: 136

Thanks Svend that did the trick! I owe you one...
Tom
jiju ka
Ranch Hand

Joined: Oct 12, 2004
Posts: 306
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

Joined: Jul 08, 2003
Posts: 24183
    
  34

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?


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Collection that keeps order
 
Similar Threads
binarysearch
Manipulations with array list.
Generics
List interface
getting the value of string array out of object array