我正在尝试修改mutableListOf
中的所有数据,但没有成功。
对于我阅读的内容,可能是:The mapping operation returns a modified list by applying a transform function on each element of the list.
我的代码是这样的:
val secValue = 110.0
val alertValue = 180.00
val maxValue = 0.111111
val mediumValue = 0.0909090909
val topValue = 0.7353
var data = mutableListOf<Double>(11.0, 28.0, 30.0, 24.0, 34.0, 31.0, 32.0)
data.map {it ->
if (it <= secValue) {it*mediumValue}
else if (it <= alertValue) {it * maxValue}
else {it * topValue}
}
最佳答案
我找到了解决方案:
var result = data.map {...}
问题是map函数返回的是
List<T>
而不是MutableList<T>
关于android - 无法在 Kotlin 映射列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53616801/