an idiomatic way to initialize a Scala ArrayBuffer?

Viewed 5294

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&#91;Int&#93;()<br>
a.appendAll(Nil.padTo(100, -1))

I'd like to see something more like this:

val a = ArrayBuffer(List(-1) * 100)
1 Answers
Related