sort by parameter

I want sort a list of an object that has, for exemple, three string attributes. How can i sort the list by the attribute selected? Is there a class which can it? Or i must implement it?
[192 byte] By [snoopybad77a] at [2007-10-3 3:58:10]
# 1

Ok, it was enoght a little serching....

java.util.List data = new java.util.ArrayList();

data.add(new Date());

data.add(new Date());

data.add(new Date());

java.util.Collections.sort(data, new _SortDate());

class _SortDate implements java.util.Comparator {

public SortDate() {}

public int doCompare(Date oo1, Date oo2) {

if (oo1.getTime() > oo2.getTime())

return 1;

else

if (oo2.getTime() > oo1.getTime())

return -1;

else

return 0;

}

}

snoopybad77a at 2007-7-14 21:56:38 > top of Java-index,Core,Core APIs...
# 2

Date implements Comparable.

So, all you need is:

java.util.List data = new java.util.ArrayList();

data.add(new Date());

data.add(new Date());

data.add(new Date());

java.util.Collections.sort(data);

Please use code tags (see button above posting box).

If you want it to sort in the other direction (I didn't check which way yours goes), change the last line to:

java.util.Collections.sort(data, Collections.reverseOrder());

MLRona at 2007-7-14 21:56:38 > top of Java-index,Core,Core APIs...