I would like to initialize an ArrayBuffer with value -1 in indexes 0 through 99. Is there a simple, idiomatic way to do so?
This works, but it’s a bit crufty:
val a = new ArrayBuffer[Int]()<br>
a.appendAll(Nil.padTo(100, -1))
I’d like to see something more like this:
val a = ArrayBuffer(List(-1) * 100)
1 Answer