August 2018
Beginner
178 pages
4h 56m
English
Maps are collections that associate keys to values. They have similar implementations to Sets. There is the most common HashMap class, an implementation that preserves insertion order when iterating; the LinkedHashMap; and the sorted version, the TreeMap. The performance of these classes is the same as with their Sets siblings. The Kotlin standard library has these functions for initializing immutable maps:
val map = mapOf(1 to "one", 2 to "two")val hashMap = hashMapOf(3 to "three", 4 to "four")val linkedMap = linkedMapOf(5 to "five", 6 to "six")val sortedMap = sortedMapOf(7 to "seven", 8 to "eight")val empty = emptyMap<Int, String>()
All these functions accept variable arguments of a Pair type to initialize the maps. We used the to ...
Read now
Unlock full access