```intervals = [[1,3],[2,6],[8,10],[15,18]] Arrays...
# getting-started
a
Copy code
intervals = [[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?
a
something like
val sorted = intervals.sortedDescendingBy{it.first()}
should do it
l
sortByDescending
to sort the current array,
sortedByDescending
to generate a list without affecting the original array
a
Thank you.
j
based on the first index
Note 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
.