0

how to sort the entire element of coloumn in 2-d array

In java programming language

29th Jun 2020, 1:56 PM
Ridhi Shree
Ridhi Shree - avatar
2 ответов
0
Can you show an illustration? I don't think I'm understanding your intention ...
29th Jun 2020, 2:33 PM
Ipang
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);
29th Jun 2020, 5:34 PM
zemiak