How to work with multidimensional arrays in Scala?

0 votes
Can anyone provide an example how to work with multidimensional arrays in Scala?
Jul 30, 2019 in Apache Spark by Dipan
183 views

1 answer to this question.

0 votes

Hi,

Here is an example you can follow:

scala> var a=ofDim[Int](3,3)

a: Array[Array[Int]] = Array(Array(0, 0, 0), Array(0, 0, 0), Array(0, 0, 0))

Now, let’s fill in some values.

scala> for(i<-0 to 2){

| for(j<-0 to 2){

| a(i)(j)={i+j}

| }

| }

scala> a

res10: Array[Array[Int]] = Array(Array(0, 1, 2), Array(1, 2, 3), Array(2, 3, 4
answered Jul 30, 2019 by Gitika
• 41,080 points

Related Questions In Apache Spark

0 votes
1 answer

How to declare sets with value in Scala?

Hey, You can follow this code: scala> var s=Set(1,4,4,3) s: ...READ MORE

answered Jul 30, 2019 in Apache Spark by Gitika
• 41,080 points
77 views
0 votes
1 answer

How to work with Matrix Multiplication in Apache Spark?

Hey, You can follow this below solution for ...READ MORE

answered Jul 31, 2019 in Apache Spark by Gitika
• 41,080 points
3,114 views
0 votes
12 answers

How to create new column with function in Spark Dataframe?

val coder: (Int => String) = v ...READ MORE

answered Apr 4, 2019 in Apache Spark by anonymous

edited Apr 5, 2019 by Omkar 58,532 views
0 votes
1 answer

How to calculate the result of formula with Scala?

Hi, You can use a simple mathematical calculation ...READ MORE

answered Jul 1, 2019 in Apache Spark by Gitika
• 41,080 points
192 views
+1 vote
2 answers
+1 vote
1 answer

Hadoop Mapreduce word count Program

Firstly you need to understand the concept ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 10,950 points
6,061 views
0 votes
1 answer

hadoop.mapred vs hadoop.mapreduce?

org.apache.hadoop.mapred is the Old API  org.apache.hadoop.mapreduce is the ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 10,950 points
923 views
+1 vote
11 answers

hadoop fs -put command?

put syntax: put <localSrc> <dest> copy syntax: copyF ...READ MORE

answered Dec 7, 2018 in Big Data Hadoop by Aditya
38,875 views
0 votes
1 answer

How to print loop with condition in scala?

Hi, Yes, in scala there is a guard condition where ...READ MORE

answered Jul 5, 2019 in Apache Spark by Gitika
• 41,080 points
84 views
0 votes
1 answer

How to concatinating Arrays in scala?

Hey, We can append a Scala array to ...READ MORE

answered Jul 25, 2019 in Apache Spark by Gitika
• 41,080 points
78 views