fun <T> mutableListOf(): MutableList<T>
Returns an empty new MutableList.
import kotlin.test.*
fun main(args: Array<String>) {
//sampleStart
val list = mutableListOf<Int>()
println("list.isEmpty() is ${list.isEmpty()}") // true
list.addAll(listOf(1, 2, 3))
println(list) // [1, 2, 3]
//sampleEnd
}
fun <T> mutableListOf(vararg elements: T): MutableList<T>
Returns a new MutableList with the given elements.
import kotlin.test.*
fun main(args: Array<String>) {
//sampleStart
val list = mutableListOf(1, 2, 3)
println(list) // [1, 2, 3]
list += listOf(4, 5)
println(list) // [1, 2, 3, 4, 5]
//sampleEnd
}
© 2010–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/mutable-list-of.html