【发布时间】:2017-12-04 12:09:02
【问题描述】:
我希望在 Kotlin 中将 List<String> 转换为 List<Int>。
val stringArray = "1 2 3 4 5 6".split(" ")
val intArray = MutableList<Int>(0, {0})
for (item in stringArray) {
intArray.add(item.toInt())
}
上面的方法可以做到,但感觉好像有更好的方法可以做到这一点(可能使用 lambdas 和流?)。
【问题讨论】: