Android Studio(Kotlin)如何将StringArray转换为MutableList

时间:2017-06-22 17:26:08

标签: android kotlin

我想从StringArray获取Resources并将其转换为MutableList

我尝试了以下代码

var morality = mutableListOf(activity.resources.getStringArray(R.string.morality))

但它给我一个错误说

Type mismatch Required: String? Found: ArrayOut<(out)String!>!

1 个答案:

答案 0 :(得分:6)

我用

解决了这个问题
var namesAndAges = ["Tom": 25, "Michael": 35, "Harry": 28, "Fabien": 16]
var namesOfAge = namesAndAges.filter { $0.value > 18 }.map{ $0.key }

print(namesOfAge)