我有一个mutableListOf<MutableList<Int>>
在kotlin
. 如何从这个列表中弹出最后一个元素?我试过 removeAt 但它没有用。
fun main() {
val intervals:List<List<Int>> = listOf(listOf(2,9), listOf(1,8), listOf(-4, 234), listOf(22,1))
println(intervals)
var sortedIntervals = intervals.toMutableList().sortedWith(Comparator<List<Int>>
{a, b -> a[0].compareTo(b[0])})
println(sortedIntervals)
sortedIntervals = sortedIntervals.map() {it -> it.toMutableList()}
println(sortedIntervals.last())
sortedIntervals.removeAt(sortedIntervals.size-1)
println(sortedIntervals)
}