Hi,
I have some a 2d array that I want to sort by one of the collums
eg:
Before Sorting: After Sorting:
1 10 9 3
2 3 8 4
3 9 4 8
4 8 3 9
5 4 1 10
I looked at the standard util.array methods, and they didn't seem to work with 2d arrays - you couldn't just specify a key collumn...
Some poeple seem to have sorted it using a comparator, but I'm a bit bogged down. This is my attempt, but I think it is very wrong .... any ideas?
(sum is my 2d array)
Arrays.sort(sum, new Comparator() {
public int compare(Object o1, Object o2) {
return ( (o1[1]).
compareTo( (o2[1])));
}
});
I have some a 2d array that I want to sort by one of the collums
eg:
Before Sorting: After Sorting:
1 10 9 3
2 3 8 4
3 9 4 8
4 8 3 9
5 4 1 10
I looked at the standard util.array methods, and they didn't seem to work with 2d arrays - you couldn't just specify a key collumn...
Some poeple seem to have sorted it using a comparator, but I'm a bit bogged down. This is my attempt, but I think it is very wrong .... any ideas?
(sum is my 2d array)
Arrays.sort(sum, new Comparator() {
public int compare(Object o1, Object o2) {
return ( (o1[1]).
compareTo( (o2[1])));
}
});