techie01
08/18/2017, 11:59 AMkrissrex
08/18/2017, 1:20 PMarrayListOf
if you explicitly need an ArrayList:
val arrayList: ArrayList<Int> = arrayListOf(1,2,3)
Use mutableListOf
if you just need a list that you can change:
val list = mutableListOf(1,2,3)
Use listOf
if you need a list that is imutable (which means you can't add or remove from it):
val list = listOf(1,2,3)
krissrex
08/18/2017, 1:21 PMarrayListOf
is probably needed if you use a java library that needs it. Otherwise, MutableList
is wiser to use in kotlintechie01
08/18/2017, 1:21 PMtechie01
08/18/2017, 1:21 PMkarelpeeters
08/18/2017, 1:44 PMArrayList
is always mutable.