[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: sorting arrays
Change your Comparator class's compare method so that it returns 1 if the
first date is null (thus the first date will be greater and show up at the
bottom of the list).
If you are doind descending order then you will need to have your Comparator
return -1 is the date is null (thus date will be lesser and show up at the
bottom of the list).
This should work out pretty well. Let me know if you have any problems (or I
screwed something up).
BAL
>From: Wade Steele <wsteele3@csc.com>
>To: ajug-members@www.ajug.org
>Subject: sorting arrays
>Date: Tue, 30 Apr 2002 15:58:00 -0400
>I need some help sorting an array of objects by column name. I'm currently
>using the Arrays.sort(Array, Comparator) method. Right now it is sorting
>ascending, which is fine. However, I need to sort a date column decending.
>Here's the catch. Not all of the objects in the array contain a value in
>the date field. That being said, if I sort ascending, the empty ones will
>show up at the top of the list, followed by the most recent date, and so
>on.
>
>How can I sort this array of objects by the date field so that, whether
>ascending or descending, the objects that have do not have date values will
>always get tagged on to the bottom of the list? Maybe this isn't possible
>without tearing apart the array and removing the ones that don't have
>values, sorting the ones with values how I want, and then appending the
>empty date objects.
>
>Any help would be appreciated.
>
>thanks
>
>Wade
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.