https://kotlinlang.org logo
#getting-started
Title
# getting-started
g

gabin

10/10/2023, 3:09 PM
Is there an idiomatic way to create generic mutable list of nulls? I did in the following way:
Copy code
private fun <T> mutableListOfNulls(size: Int) = (0..<size).map<Int, T?> { null }.toMutableList()
but I guess there should be simpler solution
j

Joffrey

10/10/2023, 3:10 PM
There is MutableList:
Copy code
val list = MutableList<YourType?>(size) { null }
👍 1
g

gabin

10/10/2023, 3:12 PM
yay, thanks!