1

Is it possible to create a multidimensional array in scala without using the "Array()"

Like this in java:

int[][] myIntArray = {
    {1, 2, 3},
    {4, 5, 6},
    {7, 8, 9}
};
Busti
  • 5,492
  • 2
  • 21
  • 34

1 Answers1

8

If i understood correctly, you dont want to declare the array repeating Array a lot of times.

You can try this:

val > = Array

val x: Array[Array[Int]] = >(
  >(1, 2, 3),
  >(4, 5, 6),
  >(7, 8, 9)
)

Source (There are other suggestions also)

Community
  • 1
  • 1
JosEduSol
  • 5,268
  • 3
  • 23
  • 31
  • This is exactly what I wanted to do. I just couldn't find it anywhere. – Busti Sep 12 '14 at 23:51
  • Hi JosEdu, out of curiosity I'm asking this, Can't we declare the above example like this, ` val > = Array; val x: >[>[Int]] = >( >(1, 2, 3), >(4, 5, 6), >(7, 8, 9) )` – user3366706 Sep 13 '14 at 16:46