I want to know how to make a resizeable two-dimensional array in Kotlin.
C++ example: vector< vector
Kotlin has separate List and MutableList interfaces, as explained here, for example. ArrayList
is a MutableList
, you just have to save it as a MutableList
variable in order to be able to access methods that mutate it:
val seqList: MutableList> = ArrayList() // alternatively: = mutableListOf()
seqList.add(mutableListOf(1, 2, 3))
Also note the mutableListOf and arrayListOf methods in the standard library, which are handy for creating lists instead of directly using the constructor of, say, ArrayList
.