0% found this document useful (0 votes)
11 views11 pages

Scala Arrays: Creation and Accessing

The document discusses different ways to create and populate arrays in Scala including using the Array keyword followed by elements in parentheses, the new keyword, the range and fill methods, and converting to an array with toArray. It also covers accessing elements and getting the length of an array.

Uploaded by

himanshu07170
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views11 pages

Scala Arrays: Creation and Accessing

The document discusses different ways to create and populate arrays in Scala including using the Array keyword followed by elements in parentheses, the new keyword, the range and fill methods, and converting to an array with toArray. It also covers accessing elements and getting the length of an array.

Uploaded by

himanshu07170
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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)

You might also like