Sets are iterables that contain no duplicate elements. Sets automatically have access to these methods: contains, apply, subsetOf. Learn why using Sets in Scala can be a great benefit.
- [Instructor] When working with Scala,…we can also create sets of values…and we can also use the map data type in Scala.…Let's start with sets.…Sets are iterables that contain no duplicate elements.…They automatically have access to the methods…contains, apply, and subset of.…Let's create a set that contains a list of fruit.…So I'm going to do val fruit is equal to…the set that contains these fruits:…apple,…orange,…peach,…and let's put in a banana.…
Since my set did not have any duplicates,…there was no work for Scala to do,…but if there was duplicates,…it would strip them out.…So, now I have a set called fruit…that contains these four fruits.…If I type in the name of my set,…and in parentheses, I put in a value,…the default function that's called on a set is the contains.…When I save the file, it will actually check…to see if peach is an element in my set,…and it returned a Boolean variable of true…since peach was one of my elements.…
Let's try it again with a different fruit.…Let's say fruit, and this time, let's say potato.…
- Installing Scala
- Integrating with IDEs
- Creating variables
- Using special functions
- Basic types and operations
- Tuples, sets, maps, arrays, and lists
- Classes, fields, and methods
- Singleton objects
Skill Level Intermediate
1. Why Scala?
2. Scala Basics
3. More Scala Basics
4. Objects with Scala
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.