The Array
Collection
in SCALA
AMRITPAL SINGH
Introduction
Arrays in Scala are collections
which come under the sequence
class.
Introduction
They are a mutable collection,
hence, when elements in an array
are modified, the original array is
updated.
Creating and Populating an Array
keyword Array followed by () in which
mention the elements you want to
populate your array with.
Syntax
With new
what if we don’t initially know what we
want to populate our array with?
For this, we will use the new keyword.
Using range
val array1 = [Link](0, 5)
//range(start, number of elements)
[Link](println)
Using fill
val array3 = [Link](2)("UBD")
//fill(number of elements)(value)
[Link](println)
Using toArray
val array4 = "hello".toArray
//converts arguments to an array
[Link](println)
Accessing Elements of an Array
Length of an Array
val intArray = Array(17, 34, 23, 6,
50)
val len = [Link]
println(len)