yeh. java.util.Collections.sort(List, Comparator). you'd need to write a quick comparator for your class, but since you want to sort on Strings anyway, it could just delegate down to that
public class MyClassComparator implements Comparator<MyClass> {
public int compare(MyClass first, MyClass second) {
return first.getVal1().compareTo(second.getVal1());
}
}
....
// later that day
Collections.sort(theVector, new MyClassComparator());
done. obviously I've guessed at class and method names, but you get the picture
> Perhaps your object should implement
> Comparable, and compare based on val1?
>
> /ninja'd
>
> Message was edited by:
> Aleron
heh heh not quite. your solution is slightly different, but no less valid, to mine. I prefer mine, because changing the sort criteria doesn't need any change to the class itself, but it's really down to personal preference
> heh heh not quite. your solution is slightly different, but no less valid, to mine. I > prefer mine, because changing the sort criteria doesn't need any change to
> the class itself, but it's really down to personal preference
And it's a good point too. Should the program want to sort the vector at a later date in regards to a different attribute in the class, your implementation would be the way to go.