Hi,
We can declare Scala arrays in two ways:
scala> var a:Array[Int]=new Array[Int](3)
a: Array[Int] = Array(0, 0, 0)
scala> a(4/2)=3
scala> a
res10: Array[Int] = Array(0, 0, 3)
- Define Scala Array with Values: We can also define a Scala array specifying its values in place.
scala> var a=Array(1,2,3)
a: Array[Int] = Array(1, 2, 3
)scala> a(4)
java.lang.ArrayIndexOutOfBoundsException: 4
scala> a(0)
res12: Int = 1
If you want to know more about Apache Spark Scala, It's highly recommended to go for the Apache Spark Certification today.