If your Vector object contains a set of custom class objects with a property of int and you want it to sort in ascending order, you can do it like this.
|
1 2 3 4 5 |
Collections.sort(vect, new Comparator() { public int compare(Object a, Object b) { return ( new Integer(((MyClass) a).getNumber()) ).compareTo( new Integer(((MyClass) b).getNumber())); } }); |
The getNumber() method contains the int value that will be used as basis to sort them in ascending order. To sort them in descending order, simply add a - (negative) sign after the keyword return.