| Author |
Formating a String-Array with more than one dimension
|
Ben Klug
Ranch Hand
Joined: Jan 28, 2002
Posts: 45
|
|
Hello, how can i sort this array 'o' by the first colmn?? //******************************** String o[][] = new String[3][2]; o[0][0]="1111111111"; o[0][1]="eins"; o[1][0]="0000000000"; o[1][1]="zwei"; o[2][0]="2222222222"; o[2][1]="drei"; for (int i = 0; i < o.length ; i++){ System.out.println(o[i][0] + "||" + o[i][1]); } //******************************** thanks in advance Ben
|
 |
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18670
|
|
|
The easiest way is to create a java.util.Comparator which compares the first entries in two String[] arrays. Then use java.util.Arrays.sort(Object[], Comparator) to sort the array quickly, with minimal fuss. This may a bit advanced for the "Beginner" forum, but it's worth the effort to learn how Comparators work.
|
"I'm not back." - Bill Harding, Twister
|
 |
 |
|
|
subject: Formating a String-Array with more than one dimension
|
|
|