Re: Sort java objects in an Array
Wednesday, September 1, 2004 10:46 PM
By implementing the comparable interface, and thereby overloading the compareTo method, you are only setting the natural ordering of ur object of type Employee.
If you need to sort by various data members then you need to create comparators for each of them.
Say if u have set the natural order emp_name wise, then u need to create 2 more comparators for desg, and salary.
A comparator is again a simple class that extends from java.util.Comparator.
To facilitate descending sorting, u need to write a separate comparator again.
Hope that helps.