Multidimensional Array is basically an array storing the data in matrix format. For, matrices and table we need multidimensional array. We can create multidimensional array by using Array.ofDim and Array of Array method.
val arrayname = Array.ofDim[data_type](number of rows, number of cols)
var arrayname = Array(Array(elements), Array(elements))
Scala has a method Array.ofDim to create a multidimensional array. This approach can be used to create arrays of up to five dimensions. Required we need to know the number of rows and columns at creation time. After declaring the array, we add elements to it .
(0,0)=2 (0,1)=7 (1,0)=3 (1,1)=4
This gives more control of the process and lets us create “ragged” arrays (where each contained array may be a different size). We can also create a multidimensional array by using Array of Array. In the example below, we have created a multidimensional array using Array of Array.
0 2 4 6 8 1 3 5 7 9
Now, let us consider an example showing the element with (row, column)
(0,0)=0 (0,1)=2 (0,2)=4 (0,3)=6 (0,4)=8 (1,0)=1 (1,1)=3 (1,2)=5 (1,3)=7 (1,4)=9
- Scala Tutorial – Learn Scala with Step By Step Guide
- Scala | Arrays
- Scala short <(x: Short): Boolean
- Scala short <(x: Char): Boolean
- Scala Extractors
- Scala | Partially Applied functions
- Scala String indexOf(String str) method with example
- Scala String contentEquals() method with example
- Scala Keywords
- Scala Int /(x: Int) method with example
- Scala Int /(x: Short) method with example
- Program to print Java Set of characters in Scala
- Scala Map size() method with example
- Scala SortedMap addString() method with a start, a separator and an end with example
- Scala Iterator addString() method with example
- Scala String substring(int beginIndex, int endIndex) method with example
- Scala | Functions Call-by-Name
- Program to convert Java list to an iterator in Scala
- Scala Set &() method with example
- Scala | Type Inference
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.