From the course: Scala Essential Training for Data Science

Unlock this course with a free trial

Join today to access over 25,000 courses taught by industry experts.

Operations on arrays, vectors, and ranges

Operations on arrays, vectors, and ranges

From the course: Scala Essential Training for Data Science

Operations on arrays, vectors, and ranges

- [Instructor] Now, let's work with Scala arrays, vectors and ranges. Scala arrays are index collections of values, much like you will find in other programming languages. Now, arrays are mutable collections, so we can alter them. Let's work with an array of temperatures. And I'll start by creating a value and we'll shorten the variable name to temps for temperatures. And we'll implicitly set this to an array of integers by specifying 50, 51, 56, 53, and 40. Now, arrays in Scala are zero based, so getting the array value at index one returns the second item in the array. For example, temps(1) will return 51 while temps(0) will actually return the first item in the array. Now, Scala, as we mentioned, is an object-oriented language. So variables and values, including arrays, are objects and they have methods associated with them. So to find the length of an array, for example, we can use the length method and we invoke that by typing the name of the array followed by a period, and then…

Contents