Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an instanciable MutableList in Kotlin, avoiding java api?

Tags:

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.

like image 546
Jules Sam. Randolph Avatar asked Feb 25 '15 00:02

Jules Sam. Randolph


People also ask

How does Kotlin define MutableList?

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.

What is the difference between ArrayList and MutableList in Kotlin?

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.

Is list immutable in Kotlin?

In Kotlin, all non-mutable collections, such as List, are compile-time read-only by default, and not immutable.

What is MutableList in Java?

A MutableList is an extension of java. util. List which provides methods matching the Smalltalk Collection protocol.


1 Answers

Try to use mutableListOf or arrayListOf.

like image 162
bashor Avatar answered Oct 08 '22 01:10

bashor