Learn
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
setOf
keyword and indicates a set whose values cannot change throughout a program. - A mutable set is declared with the
mutableSetOf
keyword and indicates a set whose values can be altered. - Elements within a set can be accessed using the
elementAt()
orelementAtOrNull()
functions. - The
addAll()
andadd()
functions are used to add elements to a collection. - The
first()
andlast()
functions return the first and last elements of a collection. - The
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.
Instructions
Click Up Next when you’re ready to move on.
Take this course for free
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.