| Author |
Sorting a multi-dimensional array
|
Bill Brasskey
Ranch Hand
Joined: Jun 01, 2004
Posts: 47
|
|
Hi I have a multi-dimensional String array with 3 cols, x rows. The value in the 3rd col is a number. I want to sort the records (rows) according to this value. Arrays.sort won't accomodate. Any nudge in the right direction will be GREATLY appreciated. -Brasskey
|
 |
Nick George
Ranch Hand
Joined: Apr 04, 2004
Posts: 815
|
|
Well, remember that a multi-dimensional array acts like (is?) an array of arrays. In a[][], a[2] is an array. Consider iterating through the rows, sorting them. [ December 22, 2004: Message edited by: Nick George ]
|
I've heard it takes forever to grow a woman from the ground
|
 |
David Harkness
Ranch Hand
Joined: Aug 07, 2003
Posts: 1646
|
|
|
Your easiest bet to save having to write your own three-column sort routine would be to create a class to hold the three values. Have it either implement Comparable using the number column (or write a separate Comparator). This way you can use Arrays.sort()
|
 |
Bill Brasskey
Ranch Hand
Joined: Jun 01, 2004
Posts: 47
|
|
Hi: Thanks much for the replies. I ended up creating a small class that implements comparable, and was able to achieve the result I was after. Thanks again, -Brasskey
|
 |
 |
|
|
subject: Sorting a multi-dimensional array
|
|
|