aspose file tools*
The moose likes Beginning Java and the fly likes Collections - I just don't understand! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Collections - I just don Watch "Collections - I just don New topic
Author

Collections - I just don't understand!

Jeremy Donaldson
Greenhorn

Joined: Jun 21, 2001
Posts: 11
I'm working through the exercises from the cattle drive and I'm working on Assignment OOP-3. It says to use the collections class to sort my text. I'm not quite sure how this is done when you don't actually create an instance of a collection. How do I call upon the methods for this class in order to sort data that I have with in an ArrayList. Any hints or tips would be great.
Thanks! Here is my current code snippet.
[Cattle Drive code deleted by Cindy]
I'm sorry, but posting Cattle Drive code is a no-no. You just need to think how to phrase your question generically so that us folks not in the "know" can try to help .
[This message has been edited by Cindy Glass (edited July 09, 2001).]
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Have you looked at SortedSet and SortedMap instead of ArrayList?


"JavaRanch, where the deer and the Certified play" - David O'Meara
Richard Boren
Ranch Hand

Joined: Mar 01, 2001
Posts: 233
First, why not ask this question over at the Cattle Drive (College) forum.
The Collections class is not intend to be instantiated.
This is straight from the Collections source:

All the Collections´┐Ż methods are static so that a Collections object is not required to use them.
As for the sort method it takes a List object as an argument. You use the sort method like any other static method as follows:
Collections.sort( yourArrayList ) ;
Here is a link to the API docs on collections www.javasoft.com/products/jdk/1.2/docs/api/java/util/Collections.html
Hope this helps.
Jeremy Donaldson
Greenhorn

Joined: Jun 21, 2001
Posts: 11

Thanks Richard. I've done the very same thing but once I reprint the values it is not sorting them like it should. It still just appears in the order that the values where entered into the ArrayList.
Jeremy Donaldson
Greenhorn

Joined: Jun 21, 2001
Posts: 11
nevermind I got it figured out, thanks again
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Collections - I just don't understand!