Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
References¶
LinkedHashMap preserves the insertion order (which is similar to dict in Python 3.7+).
val map = hashMapOf(1 to "x", 2 to "y", -1 to "zz")
println(map){-1=zz, 1=x, 2=y}
nullLinkedHashMap¶
Notice that the order of keys is the same as their insertion order!
val map = linkedMapOf(
1 to "x", 2 to "y", -1 to "zz"
)
println(map){1=x, 2=y, -1=zz}
for ((key, value) in map) {
println("$key = $value")
}1 = x
2 = y
-1 = zz
map.forEach {
(key, value) -> println("$key = $value")
}1 = x
2 = y
-1 = zz
val list: List<String> = map.map {
(key, value) -> value
}
list[x, y, zz]Count Occurences of Elements in a Collection¶
listOf(1, 1, 3, 2, 1, 2, 4).groupingBy { it }.eachCount()Loading...