How to add an item to an ArrayList in Kotlin?

后端 未结 4 1398
半阙折子戏
半阙折子戏 2021-01-31 01:13

How to add an item to an ArrayList in Kotlin?

4条回答
  •  伪装坚强ぢ
    2021-01-31 01:28

    If you want to specifically use java ArrayList then you can do something like this:

    fun initList(){
        val list: ArrayList = ArrayList()
        list.add("text")
        println(list)
    }
    

    Otherwise @guenhter answer is the one you are looking for.

提交回复
热议问题