What is ofDim in Scala

0 votes
Can someone explain what is ofDim in Scala?
Jul 24, 2019 in Apache Spark by Tejas
1,086 views

1 answer to this question.

0 votes

Hey,

ofDim() is a method in Scala that lets us create multidimensional arrays. Since these let us store data in more than one dimension, we can store data like in a matrix. Let’s take an example.

scala> import Array.ofDim

import Array.ofDim

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

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

scala> var k=1

k: Int = 1

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

| for(j<-0 to 2){

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

| k+=1

| }

| k-=1

| }

scala> a

The output will be like:

res12: Array[Array[Int]] = Array(Array(1, 2, 3), Array(4, 5, 6), Array(7, 8, 9))

answered Jul 24, 2019 by Gitika
• 65,850 points

Related Questions In Apache Spark

0 votes
1 answer

What is exception propagation in Scala?

Hi, When a function experiences an exception, it ...READ MORE

answered Jul 25, 2019 in Apache Spark by Gitika
• 65,850 points
108 views
0 votes
1 answer

What is BitSet in Scala?

Hey, A BitSet is a set of non-negative ...READ MORE

answered Jul 25, 2019 in Apache Spark by Gitika
• 65,850 points
109 views
0 votes
1 answer

What is Streams in Scala?

Hi, A stream is a lazy list as ...READ MORE

answered Jul 25, 2019 in Apache Spark by Gitika
• 65,850 points
107 views
0 votes
1 answer

What is recursion in Scala function? How does it works?

Hey, A Scala function involves recursion when it ...READ MORE

answered Jul 25, 2019 in Apache Spark by Gitika
• 65,850 points
133 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
• 11,380 points
6,634 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
• 11,380 points
1,046 views
+2 votes
11 answers

hadoop fs -put command?

Hi, You can create one directory in HDFS ...READ MORE

answered Mar 16, 2018 in Big Data Hadoop by nitinrawat895
• 11,380 points
45,304 views
0 votes
1 answer

What is “Unit” and “()” in Scala?

Hey, Unit is a subtype of scala.anyval and ...READ MORE

answered Jul 24, 2019 in Apache Spark by Gitika
• 65,850 points
144 views
0 votes
1 answer

What is the advantage of having immutability in design for Scala programming language?

Hi, Scala uses immutability by default in most ...READ MORE

answered Jul 24, 2019 in Apache Spark by Gitika
• 65,850 points
120 views