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).]
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.
Joined: Jun 21, 2001
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.