我正在使用 removeAt 函数,它工作正常,但突然编译器开始抛出错误未解决的参考:removeAt
这是代码:
fun main() {
val nums = mutableListOf(-3, 167, 0, 9, 212, 3, 5, 665, 5, 8) // this is just a list
var newList = nums.sorted() // this is the sorted list
var finall = mutableListOf<Int>() // this is an empty list that will contain all the removed elements
for(i in 1..3) {
var min: Int = newList.removeAt(0) // element removed from newList is saved from min variable
// above line is producing the error
finall.add(min) // then the min variable is added to the empty list created before
}
println(finall)
println(newList)
}
我研究了一堆文档,但我找不到我的错误