Akshitha Mishra wrote:If the sortField value is String, then I want it be sorted by String, but if the sortField value is date, then I want it to be sorted by Date.
I understand that; and if the field is
Comparable (and both Strings and Dates are), then you can probably do it. For example, I wrote the following class a while ago:
Now it may not look like much, but it allows you to create a
Comparator for any
Comparable type that emulates its "natural" order; and
that means that you can use Comparators pretty much everywhere.
But the collections.sort that I am using works only for strings and not when I need it to be sorted by date.
Then you're doing something wrong, because it will sort by either; just not at the same time, or with
the same Comparator. Now if
that's what you want, then you'll probably need some pretty fancy code...and it may well be slow.
However, you still haven't explained
what you're trying to do. Perhaps these are easier questions:
Why do you need to do this? And why can't you just write two different
sort() calls?
Winston