Tag: mutablemap

Kotlin基础知识:如何添加或设置一个Map的元素?

我想用特定的键值对添加/设置可变映射的元素。 到目前为止,我发现我可以使用plus运算符和Pair数据类型来添加新元素: var arr3:Map<Any, Any> = mutableMapOf() arr3 += Pair("manufacturer", "Weyland-Yutani") //also, the "to" operator works too: //arr3 += ("manufacturer" to "Weyland-Yutani") 但是,我找不到如何修改或添加新的键值对: arr3["manufacturer"] = "Seegson" // gives an error( Kotlin: No set method providing array access) arr3["manufacturer"] to "Seegson" // compiles, but nothing is added to the array 请你详细说明我该怎么做?