• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Collections - I just don't understand!

 
Jeremy Donaldson
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you looked at SortedSet and SortedMap instead of ArrayList?
 
Richard Boren
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nevermind I got it figured out, thanks again
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic