fun differentGame(row: Int, column: Int, player: String) {
val list: MutableList<MutableList<String>> = mutableListOf(
mutableListOf("","","","",""),
mutableListOf("","","","",""),
mutableListOf("","","","",""),
mutableListOf("","","","",""),
mutableListOf("","","","",""),
mutableListOf("","","","",""),
mutableListOf("","","","",""),
mutableListOf("","","","",""),
mutableListOf("","","","","")
)
val iterator = list.iterator()
while (iterator.hasNext()){
val item = iterator.next()
if (list.size > row){
iterator.remove()
} else break
}
}
有这样的代码。在迭代器的帮助下,行被正常删除,但是如何删除或添加列?我试图通过标准 for 循环删除行和列,但它会在那里引发 ConcurrentModificationException。谷歌搜索并通过迭代器找到了异常的解决方案