Using Map
A map keeps a collection of key-value pairs. Much like the way Kotlin provides a read-only immutable interface and a read-write mutable interface for the JDK List, the language also provides two interfaces for the JDK Map. All methods of the JDK Map interface are available through the mutable interface, and the read-only methods are available through the immutable interface.
You may use mapOf() to create a map and get a reference to the read-only interface Map<K, V>. Alternatively, use mutableMapOf() to get access to MutableMap<K, V>. Also, you may obtain a reference to the JDK HashMap using hashMapOf(), LinkedHashMap using linkedMapOf(), and SortedMap using sortedMapOf().
Let’s create an example using the immutable/read-only interface ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access