Map and MutableMap

The Map interface in the collections framework is a bit different than all others interfaces we have covered earlier; unlike others it works with key-value pairs. No, this is not similar to PairPair is just a pair of two values combined together, while a map is a collection of key-value pairs.

In a map, keys are unique and cannot be duplicated. If you add two values with the same key, then the later one will replace the previous one. Values, on the other hand can be redundant/duplicate. The reason behind this behavior is that in a map, a value is stored and retrieved with respect to its key, so redundant keys will make it impossible to distinguish them from each-other and to fetch their values.

The declaration of Map ...

Get Functional Kotlin now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.