Is there any way to build dynamic multi-dimensional arrays in Scala? I know arrays in Scala must be initialized in its sizes and dimensions, so I don\'t want that. The data stru
You may create an array of 2 dims dynamically like this:
val aa : Array[Array[Int]] = Array.ofDim (3, 4)
Well, yes, I see, the size is fixed. How about that:
val i = random.nextInt (5) + 1
val j = new GregorianCalendar (). get (Calendar.DAY_OF_WEEK)
val aa : Array[Array[Int]] = Array.ofDim (i, j)
Yes, it is bound to two dimensions. How would you use an array of previously unknown dimension?
Well - at least, you can:
val aa : Array [Int] = Array.ofDim (2)
aa: Array[Int] = Array(0, 0)
val aaa = Array.fill (3) (aa)
aaa: Array[Array[Int]] = Array(Array(0, 0), Array(0, 0), Array(0, 0))