Great job! In this lesson, we’ve learned the following concepts:
- A set is an unordered Kotlin collection that stores unique elements.
- An immutable set is declared with the
setOfkeyword and indicates a set whose values cannot change throughout a program.
- A mutable set is declared with the
mutableSetOfkeyword and indicates a set whose values can be altered.
- Elements within a set can be accessed using the
add()functions are used to add elements to a collection.
last()functions return the first and last elements of a collection.
clear()function removes all elements from a collection.
You’ve now covered the second major collection that exists in Kotlin as well as many other programming languages. Feel free to utilize the empty Review.kt file and output terminal on the right to hone your understanding of sets and practice writing Kotlin code.
Click Up Next when you’re ready to move on.