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 Pair
;Â Pair
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
in Kotlin reads like interface Map<K, out V>
, the K
 value is the generic type of the key and V
is the generic type of value.
To learn more about collections, let us have a look at a few of the functions and properties. Go through the following list:
val...