how to sort any class objects( containing different attribute)!_NEWLINE_!with respect to any attribute and display as rows
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   faisal_parwani
Posted On:   Friday, May 18, 2001 03:55 AM

i have a class with different attribute such as name ,
gender , date , roll no.

now one method receive the list which contains objects
of that class , and now i have to sort them in ascending
order with respect to any of the attribute selected run
time. how can i do it .
i have to display class attribute a database records
rows but in ascending order with respect to any attribute
how can i do it.

Re: how to sort any class objects( containing different attribute)!_NEWLINE_!with respect to any attribute and display as rows

Posted By:   Christopher_Schultz  
Posted On:   Friday, May 18, 2001 08:25 AM

If you will be hitting the database each time you refresh the page, then you're better off adding an ORDER BY clause to your SQL.



Otherwise, you'll want to use the java.util.Collections class's static methods to sort your collection. You'll have to create an implementation of a Comparator to sort on the field you want to sort by (name, date, etc.).



-chris
About | Sitemap | Contact