Scala – printing arrays

In Scala 2.8, you can use the deep method defined on Array, that returns an IndexedSeq cointaining all of the (possibly nested) elements of this array, and call mkString on that:


scala> val array = Array.fill(2,2)(0)
array: Array[Array[Int]] = Array(Array(0, 0), Array(0, 0))

scala> println(array.deep.mkString("\n"))
Array(0, 0)
Array(0, 0)

The IndexedSeq returned does have a stringprefix ‘Array’ by default, so I’m not sure whether this gives precisely what you wanted.

Leave a Comment