MutableList
is an interface, but I cannot find a class in kotlin
package that implements it explicitly. Is there any? Furthermore, I would have expected to be a package-scope defined mutableListOf(varargs) symetrically to listOf(varargs). Up until now, I have to use java Collections.
To use the MutableList interface we use its function called mutableListOf() or mutableListOf<E>(). The elements of MutableList follow the sequence of insertion order and contains index number same as array.
ArrayList is a class that happens to implement the MutableList interface. The only difference is that arrayListOf() returns the ArrayList as an actual ArrayList. mutableListOf() returns a MutableList, so the actual ArrayList is "disguised" as just the parts that are described by the MutableList interface.
In Kotlin, all non-mutable collections, such as List, are compile-time read-only by default, and not immutable.
A MutableList is an extension of java. util. List which provides methods matching the Smalltalk Collection protocol.
Try to use mutableListOf
or arrayListOf
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With