I want to make sure I understand the docs. <Here> ...
# getting-started
g
I want to make sure I understand the docs. Here says that Map preserves the order of elements insertion. What I understand is that when I use
mapOf(…)
or
mutableMapOf(…)
, the order in which elements are inserted are preserved. Is that a correct statement?
k
well Map interface is not preserving order. One of implementation (LinkedHashMap) is preserving order (and it’s default one). Personally when I need ordering I’m using LinkedHaspMap explicitly to show my intentions in source code and to guarantee sorting.
linkedMapOf
g
But that’s not what the docs stated.
Copy code
The default implementation of Map – LinkedHashMap – preserves the order of elements insertion when iterating the map. In turn, an alternative implementation – HashMap – says nothing about the elements order.