The Array Collection
In the following lesson, you will learn how to use arrays in Scala.
Introduction
Arrays in Scala are collections which come under the sequence class. They are a mutable collection, hence, when elements in an array are modified, the original array is updated. However, it is important to mention here that in one-way arrays are also immutable as the size of the array cannot change.
Scala arrays are represented as Java arrays. So, the Scala array Array[Int]
, is represented as the Java array int[]
and the Scala array Array[String]
is represented as the Java array string[]
, and so on. That being said, Scala arrays have a lot more to offer and in the next two lessons, we will see exactly how that is.
Creating and Populating an Array
While there are multiple ways of populating and defining an array in Scala, the basic syntax of creating an array from scratch remains the same with the keyword Array
followed by ()
in which you mention the elements you want to populate your array with.
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy