0
how to sort the entire element of coloumn in 2-d array
In java programming language
2 Antworten
0
Can you show an illustration?
I don't think I'm understanding your intention ...
0
char[][] arr={{'B','B','B'},{'C','C','C'},{'D','D','D'},{'A','A','A'}};
//use a Comparator you wish eg
Arrays.sort(arr, Comparator.comparing(a-> a[0]) );
System.out.println(Arrays.deepToString(arr) );
//---- or for List -----:
var arr = new ArrayList<List<Character>>();
arr.add(List.of('B','B','B') );
arr.add(List.of('C','C','C') );
arr.add(List.of('D','D','D') );
arr.add(List.of('A','A','A') );
arr.sort(Comparator.comparing(a -> a.get(0) ));
System.out.println(arr);