|
|
Re: Please add some code with Mutidimensional arrays
|
Posted: Jan 29, 2008 10:04 PM
|
|
Scala doesn't have multidimensional arrays. Instead it has arrays of any element type, so you can create arrays of arrays. There are a couple of old examples in the language spec (search for "matrix"); here's some corrected code for those examples: https://lampsvn.epfl.ch/trac/scala/attachment/ticket/421/MatrixExamples.scala
There are methods for constructing arrays of arrays of arrays of ...:- val x = new Array[Array[Array[Int]]](2, 3, 4) x(0) = new Array[Array[Int]](1, 1) println( x.map(y => y.map(_.toList)).map(_.toList).toList )
List(List(List(0)), List(List(0, 0, 0, 0), List(0, 0, 0, 0), List(0, 0, 0, 0)))
|
|