I want a two-dimensional array of ArrayBuffer
Something like this:
var myRowOfStrings = new ArrayBuffer[String]
val myArrayOfRows = new ArrayBuffer[ArrayBuffer] // To store many ArrayBuffer[String]
But the Scala compiler doesn't like the second declaration:
scala> val myArrayOfRows = new ArrayBuffer[ArrayBuffer]
<console>:8: error: class ArrayBuffer takes type parameters
val myArrayOfRows = new ArrayBuffer[ArrayBuffer]
^
Have I got the syntax wrong?
Or is an ArrayBuffer of ArrayBuffer not possible?
ArrayBuffer objects require a type. It says so in the error message.
You need to tell the compiler what type of ArrayBuffer you want.
scala> import scala.collection.mutable.ArrayBuffer
import scala.collection.mutable.ArrayBuffer
scala> val myArrayOfRows = new ArrayBuffer[ArrayBuffer[String]]
myArrayOfRows: scala.collection.mutable.ArrayBuffer[scala.collection.mutable.ArrayBuffer[String]] = ArrayBuffer()
Consider doing this if its easier.
type Row = ArrayBuffer[String]
var myRowOfStrings = new Row
val myArrayOfRows = new ArrayBuffer[Row]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With