如果我有一张这样的清单
var foo = mutableListOf("John", "Wayne")
如果我想在列表顶部添加一个元素,到目前为止我正在考虑两个选项。
第一的:foo.add(0, "Twyla")
foo.add(0, "Twyla")
第二:foo = (mutableListOf("Twyla") + foo).toMutableList()
foo = (mutableListOf("Twyla") + foo).toMutableList()
我不知道上述两种选择在性能方面的表现如何,但一般推荐的方法是什么?
list arraylist kotlin
arraylist ×1
kotlin ×1
list ×1