Reputation: 45
In Java I can do something like:
long[][] foo = new long[10][]
foo[0] = new long[1]
foo[1] = new long[2]
How can I do something similar in Scala?
Upvotes: 0
Views: 70
Reputation: 44908
You can use Array.ofDim[X](d)
to create array of type X
and dimension d
:
val foo = Array.ofDim[Array[Long]](10)
foo(0) = Array.ofDim[Long](1)
foo(1) = Array.ofDim[Long](2)
or you can use new
:
val foo = new Array[Array[Long]](10)
foo(0) = new Array[Long](1)
foo(1) = new Array[Long](2)
to achieve the same.
Upvotes: 2