科特林有独立
List和
MutableList接口,解释在这里,例如。
ArrayList是一个
MutableList,您只需将其另存为
MutableList变量,即可访问对其进行变异的方法:
val seqList: MutableList<MutableList<Int>> = ArrayList() // alternatively: = mutableListOf()seqList.add(mutableListOf<Int>(1, 2, 3))
还要注意标准库中的
mutableListOf和
arrayListOf方法,它们很容易创建列表,而不是直接使用的构造函数
ArrayList。



