Woohoo! Excellent work. You’ve completed the final lesson on collection types in Kotlin. Let’s review what was covered:
- A map is a collection that stores key-value pairs of data.
- The keys within a map must be unique, however, the values can duplicate.
- An immutable map is declared with the
mapOfkeyword and indicates a map whose entries cannot change throughout a program.
- A mutable map is declared with the
mutableMapOfkeyword and indicates a Map whose entries can be altered.
- Values within a map can be accessed using shorthand
- To return all the values in a map, use the
valuesproperty. To return all the keys in a map, use the
put()function accepts a key and a value to add to a map.
remove()function accepts a key and removes the entry associated with that key.
You’ve now covered the third and final major collection that exists in Kotlin. Feel free to utilize the empty Review.kt file and output terminal on the right to hone your understanding of maps and practice writing Kotlin code.
Click Up Next when you’ve completed the review and are ready to move on.