- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Creating a multi-dimensional array
Sat, 2008-12-20, 04:58
I'm sure this is something trivial, but I can't seem to create a multi-dimensional array. The scala.Array class has constructors for them, but it won't let me do it:
scala> val data = new Array[Float](4, 4)
<console>:4: error: too many arguments for array constructor: found 2 but array has only 1 dimension(s)
val data = new Array[Float](4, 4)
^
What am I doing wrong?
You can do it like this:
val data = new Array[Array[Float]](4, 4)
Robert Kosara-2 wrote::4: error: too many arguments for array constructor: found 2 but
>
> I'm sure this is something trivial, but I can't seem to create a
> multi-dimensional array. The scala.Array class has constructors for them,
> but it won't let me do it:
>
> scala> val data = new Array[Float](4, 4)
>
> array has only 1 dimension(s)
> val data = new Array[Float](4, 4)
> ^
>
> What am I doing wrong?
>
>
-----
My scala solutions for http://projecteuler.net/ Project Euler problems:
http://eastsun.javaeye.com/category/34059 Click here