It seems that print array support is somewhat missing in Scala. If you print it, you will get the default junk that you get in Java:
scala> val array = Array.fill(2,2)(0) array: Array[Array[Int]] = Array(Array(0, 0), Array(0, 0)) scala> println(array) [[I@d2f01d
Also, you cannot use the Java toString / deepToString methods from the java.util.Arrays class: (or at least I can't figure it out)
scala> println(java.util.Arrays.deepToString(array)) <console>:7: error: type mismatch; found : Array[Array[Int]] required: Array[java.lang.Object] println(java.util.Arrays.deepToString(array))
The best solution for printing a 2D array I can do the following:
scala> println(array.map(_.mkString(" ")).mkString("\n")) 0 0 0 0
Is there a more idiomatic way to do this?
scala
I82Much Jul 25 '10 at 5:02 2010-07-25 05:02
source share