Answers for "arraylist vs mutablelist kotlin"

2

arraylist vs mutablelist kotlin

The only difference between the two is communicating your intent.

When you write val a = mutableListOf(),
you're saying "I want a mutable list, and I don't particularly 
care about the implementation". When you write, instead, val a = ArrayList(), 
you're saying "I specifically want an ArrayList".

In practice, in the current implementation of Kotlin compiling to the JVM,
calling mutableListOf will produce an ArrayList, 
and there's no difference in behaviour: once the list is built,
everything will behave the same.
Posted by: Guest on August-20-2021

Browse Popular Code Answers by Language