Resizeable two-dimensional array in Kotlin

前端 未结 1 844
情话喂你
情话喂你 2021-01-13 05:52

I want to know how to make a resizeable two-dimensional array in Kotlin.

C++ example: vector< vector > my_vector

相关标签:
1条回答
  • 2021-01-13 06:51

    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<MutableList<Int>> = ArrayList() // alternatively: = mutableListOf()
    
    seqList.add(mutableListOf<Int>(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.

    0 讨论(0)
提交回复
热议问题