Create and populate two-dimensional array in Scala

Posted by ~asteinlein on Stack Overflow See other posts from Stack Overflow or by ~asteinlein
Published on 2010-03-22T22:31:36Z Indexed on 2010/03/23 2:31 UTC
Read the original article Hit count: 273

Filed under:
|
|

What's the recommended way of creating a pre-populated two-dimensional array in Scala? I've got the following code:

val map = for {
    x <- (1 to size).toList
} yield for {
        y <- (1 to size).toList
    } yield (x, y)

How do I make an array instead of list? Replacing .toList with .toArray doesn't compile. And is there a more concise or readable way of doing this than the nested for expressions?

© Stack Overflow or respective owner

Related posts about scala

Related posts about arrays