1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| String[][] array = {
{ "def", "def", "ghi" },
{ "abc", "ghi", "jkl" },
{ "ghi", "abc", "abc" },
};
// Affichage du tableau :
for (int i=0; i<array.length; i++) {
for (int j=0; j<array[i].length; j++) {
System.out.printf("[%d][%d] %s ", i, j, array[i][j]);
}
System.out.println();
}
System.out.println();
// Tri du tableau :
Arrays.sort(array, new Comparator<String[]>(){
public int compare(String[] o1, String[] o2) {
return o1[1].compareTo(o2[1]);
}
});
// Affichage du tableau :
for (int i=0; i<array.length; i++) {
for (int j=0; j<array[i].length; j++) {
System.out.printf("[%d][%d] %s ", i, j, array[i][j]);
}
System.out.println();
}
System.out.println(); |