Hi, I have a ArrayList containing the values retreived from the DB. I need to sort the data in two levels. The primary level is the field containing the Date and if the sorted values have the same dates the data needs to be sorted with the field containing Names. How do I do it? I have used the comparator to sort individually how do I club the results?
Joined: Dec 20, 2007
Either a Comparator or Comparable (whatever is more appropriate) will do the job. If you're using a Comparator, you could do something like this:
Joined: Nov 14, 2007
Thanks for the response. But I need to retain the result of the first sort and then sort upon it. The second sort criteria should not effect the first result if there is no similar data.
Joined: Feb 20, 2006
Sort first according to date, then take the sorted list and sort that again using a simple conditional statement on the date and name. (while date is equal => sort name)
Joined: Aug 05, 2005
Originally posted by Vinitha Pai: Thanks for the response. But I need to retain the result of the first sort and then sort upon it. The second sort criteria should not effect the first result if there is no similar data.
Did you try Arman's suggestion ? I think you will find it does what you want.