android - 无法在 Kotlin 映射列表

标签 android kotlin

我正在尝试修改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/

相关文章:

android - 使用由事件组成的回调实例化实例

kotlin - 即使 encoded=true,Retrofit2 也会对查询值进行编码

android - LazyColumnFor 滚动不流畅

android - 在 ubuntu 上设置安卓

Android EditText 和 Button 在同一行

android - 如何使用 Retrofit 解析 JSON 数组?

java - nodejs和kotlin中的SHA256不同哈希

android - Kotlin - 如何在映射和过滤时跳过异常条目

android - 通知中的 PendingIntent

android - Kotlin - 如何在 "lateinit"和 "nullable variable"之间做出决定?