我想将中间0替换为1。我该怎么做?

val list = mutableListOf(0,0,0,0,0)

最佳答案

您可以尝试以下操作:

val list = mutableListOf(0, 0, 0, 0, 0)
list[list.size / 2] = 1
// after this array should look like this: (0, 0, 1, 0, 0)

10-08 14:53