stsanz
asked on
Sorting a Vector
I have a Vector of objects that I want to sort.
The only way I figured how to do this is to :
1) Convert the Vector to an Array, using vector.toArray()
2) Sort the array, using Arrays.sort()
3) Fill the Vector back with the sorted array, using a loop !
Quite tricky...
Is there any simpler way??
Thanks,
stsanz.
The only way I figured how to do this is to :
1) Convert the Vector to an Array, using vector.toArray()
2) Sort the array, using Arrays.sort()
3) Fill the Vector back with the sorted array, using a loop !
Quite tricky...
Is there any simpler way??
Thanks,
stsanz.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Keep in mind though that Collections.sort() sort according to the elements 'natural' order, which might or might not suit your needs! If you need a different, or custom sorting order for your elements you have to implement the Comparator interface and provide an instance with the call to Collections.sort(). Find more infor about Compartor at http://java.sun.com/j2se/1.4.2/docs/api/java/util/Comparator.html .
8-)