N Dimension Arrays

If you want to learn more, check out Scala Cookbook and Programming in Scala.

Create 2 x 2 Array

// Set the number of rows and columns
val rows = 2
val columns = 2

// Create an array of integers that is 2x2
val matrix = Array.ofDim[Int](rows, columns)
// View array
matrix
Array(Array(0, 0), Array(0, 0))

Add Values To Array

// First row, first column
matrix(0)(0) = 1

// First row, second column
matrix(0)(1) = 0

// Second row, first column
matrix(1)(0) = 0

// Second row, second column
matrix(1)(1) = 1
// View array
matrix
Array(Array(1, 0), Array(0, 1))