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
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
(Locked)
The advantages of Scala for data science2m 4s
-
(Locked)
Installing Scala1m 58s
-
(Locked)
Scala data types3m 22s
-
Working with data types in the Scala REPL5m 7s
-
(Locked)
Challenge Intro: Create variables27s
-
(Locked)
Solution: Create variables49s
-
(Locked)
Scala collections2m 24s
-
(Locked)
Operations on sets5m 32s
-
(Locked)
Operations on arrays, vectors, and ranges5m 54s
-
(Locked)
Operations on maps5m 4s
-
(Locked)
Challenge Intro: Create arrays, vectors, and ranges31s
-
(Locked)
Solution: Create arrays, vectors, and ranges53s
-
(Locked)
Scala expressions5m 13s
-
(Locked)
Challenge Intro: Create expressions28s
-
(Locked)
Solution: Create expressions33s
-
(Locked)
Scala functions3m 7s
-
(Locked)
Challenge Intro: Create functions40s
-
(Locked)
Solution: Create functions36s
-
(Locked)
Creating classes in Scala5m 48s
-
(Locked)
Creating operations in Scala3m 19s
-
(Locked)
Challenge Intro: Define a Class28s
-
(Locked)
Solution: Define a class30s
-
(Locked)
-
-
-
-
-