View Single Post
Old 10-21-2008, 05:28 PM   PM User | #5
shyam
Senior Coder

 
shyam's Avatar
 
Join Date: Jul 2005
Posts: 1,563
Thanks: 2
Thanked 163 Times in 160 Posts
shyam will become famous soon enough
Quote:
Originally Posted by rajeshnaidu View Post
I had done using Comparable and Comparator interfaces. But the problem here is need to handle both ascending and descending dynamically based on parameter passed.
what did you do? the scenario you describe can be pretty easily accomplished using just comparator...(its usually easier to sort it ascending and reverse the results for descending >).. )

Quote:
Originally Posted by ctbalamurali View Post
Dynamic variable can be passed to determine the the sorting order
Please find the updated sample code.
PHP Code:
package Sorting;

public class 
Student implements Comparable {
    public 
Long student_id;
    public 
String last_name;
    public 
String first_name;
    public 
boolean isAsc;
...


cmon...this isn't passing a dynamic variable :O...have you considered the case when an collection containing some students who want to be sorted ascending and others descending !!
__________________
You never have to change anything you got up in the middle of the night to write. -- Saul Bellow
shyam is offline   Reply With Quote