arrayslistkotlin

Difference between List and Array types in Kotlin


What is the difference between List and Array types?
It seems can make same operations with them (loops, filter expression, etc..), is there any difference in behavior or usage?

val names1 = listOf("Joe","Ben","Thomas")
val names2 = arrayOf("Joe","Ben","Thomas")

for (name in names1)
    println(name)
for (name in names2)
    println(name)

Solution

  • Arrays and lists (represented by List<T> and its subtype MutableList<T>) have many differences, here are the most significant ones: