what is difference between arraryListOf() and list...
# getting-started
t
what is difference between arraryListOf() and listOf()
k
Use
arrayListOf
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)
arrayListOf
is probably needed if you use a java library that needs it. Otherwise,
MutableList
is wiser to use in kotlin
t
both are kotlin
except listOf has the mutable type
k
ArrayList
is always mutable.