Collection sorting
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Si_Cal
Posted On:   Thursday, August 29, 2002 09:45 AM

This is probably a very easy question to answer but I just can't seem to get my head round it. Here goes: What I have is a collection of records (my own objects that store various bits of information). In my program I search through the collection and each record that matches the criteria I want to copy to a new collection and give it a score. When finished I want to display the results in descending score order. Using the standard collection framework what is the best approach to this problem so I don't have to implement my own custom sort routine. Is it quickest to sort when building the new collection or one big sort at the end. Your help will be greatly appreciated, Thanks.    More>>

This is probably a very easy question to answer but I just can't seem to get my head round it.

Here goes: What I have is a collection of records (my own objects that store various bits of information). In my program I search through the collection and each record that matches the criteria I want to copy to a new collection and give it a score. When finished I want to display the results in descending score order.

Using the standard collection framework what is the best approach to this problem so I don't have to implement my own custom sort routine. Is it quickest to sort when building the new collection or one big sort at the end.

Your help will be greatly appreciated,
Thanks.

   <<Less

Re: Collection sorting

Posted By:   Rob_Eamon  
Posted On:   Thursday, August 29, 2002 11:04 AM

Take a look at java.util.TreeSet. It should do what you need as long as your record class implements Comparable or you have a Comparator that can be used.
About | Sitemap | Contact