Ayden
09/24/2021, 2:21 PMintervals = [[1,3],[2,6],[8,10],[15,18]]
Arrays.sort(intervals, compareBy { it[1] })
Hi guys, may i know how can i sort it in descending order based on the first index?Alex Prince
09/24/2021, 2:26 PMval sorted = intervals.sortedDescendingBy{it.first()}
should do itLuke
09/24/2021, 2:28 PMsortByDescending
to sort the current array, sortedByDescending
to generate a list without affecting the original arrayAyden
09/24/2021, 2:31 PMJoffrey
09/24/2021, 2:38 PMbased on the first indexNote that
1
(as provided in the example) is not the first index, though. Using it.first()
as suggested gives you index 0. Just keep this in mind when you choose what to pass to sortedByDescending
.