From the course: Kotlin Essential Training: Functions, Collections, and I/O

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Sets and maps

Sets and maps

- [Instructor] Now it's time to introduce two more common data structures, sets and maps. Both these data structures are incredibly useful and widely used. We're going to explore how to create and work with both of them. Like with lists, the easiest way to create a set in Kotlin is to use a builder function. So let's define a variable called languages, and we want this to hold a set of programming language strings. So I will use the setOf function here and then I need to pass in the strings that I want to be a part of this set. So in this case, I'll pass Kotlin, Java and C++. Oops. Need to make sure that last one is wrapped in quotes. There we go. So we have a set of Kotlin, Java and C++, and because of type inference here, we don't have to explicitly define the type. But if we did, that type would look like this setOf non nullable string. Now, let's remember what is special about sets. They don't allow for…

Contents