You have:
val array = new Array[Array[Cell]](height, width)
How do you initialize all elements to new Cell("something")?
Thanks, Etam (new to Scala).
Create Array with RangeUse of range() method to generate an array containing a sequence of increasing integers in a given range. You can use final argument as step to create the sequence; if you do not use final argument, then step would be assumed as 1.
Scala arrays can be generic. which mean we can have an Array[T], where T is a type parameter or abstract type. Scala arrays are compatible with Scala sequences – we can pass an Array[T] where a Seq[T] is required. Scala arrays also support all sequence operations.
Welcome to Scala version 2.8.0.r21376-b20100408020204 (Java HotSpot(TM) Client VM, Java 1.6.0_18).
Type in expressions to have them evaluated.
Type :help for more information.
scala> val (height, width) = (10,20)
height: Int = 10
width: Int = 20
scala> val array = Array.fill(height, width){ new Cell("x") }
array: Array[Array[Cell[java.lang.String]]] = Array(Array(Cell(x), Cell(x), ...
scala>
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