Kotlin - creating a mutable list with repeating elements
another way may be:
val list = generateSequence { v }.take(4).toMutableList()
This style is compatible with both MutableList and (Read Only) List
Use:
val list = MutableList(n) {index -> v}
or, since index
is unused, you could omit it:
val list = MutableList(n) { v }