References¶
- LinkedHashMap preserves the insertion order (which is similar to dict in Python 3.7+).
In [1]:
val map = hashMapOf(1 to "x", 2 to "y", -1 to "zz")
println(map)
Out[1]:
LinkedHashMap¶
Notice that the order of keys is the same as their insertion order!
In [1]:
val map = linkedMapOf(
1 to "x", 2 to "y", -1 to "zz"
)
println(map)
In [8]:
for ((key, value) in map) {
println("$key = $value")
}
In [10]:
map.forEach {
(key, value) -> println("$key = $value")
}
In [13]:
val list: List<String> = map.map {
(key, value) -> value
}
list
Out[13]:
Count Occurences of Elements in a Collection¶
In [3]:
listOf(1, 1, 3, 2, 1, 2, 4).groupingBy { it }.eachCount()
In [ ]: