Iaroslav Postovalov
11/05/2019, 5:13 PMwbertan
11/05/2019, 5:25 PMLinkedHashMap
ensures the order which you insert elements, and HashMap
not? So maybe because you are explicitly saying you have a mutableMap
you will be adding/removing?! ¯\_(ツ)_/¯turansky
11/05/2019, 5:27 PMRuckus
11/05/2019, 5:27 PMLong time ago we defaulted all maps and sets to be linked because it was really confusing to loose order in many practical applications.
If you want a hashset for performance/memory reasons you can obtain it with hashSetOf() or toHashSet() functions.
You cannot change the default behavior of setOf in the standard library, but if you really want, you can hide it with your own explicitly imported setOf function (import my.utils.setOf), though I wouldn’t recommend it as a long term solution.
wbertan
11/05/2019, 5:28 PM/**
* Returns an empty new [MutableMap].
*
* The returned map preserves the entry iteration order.
* @sample samples.collections.Maps.Instantiation.emptyMutableMap
*/
@SinceKotlin("1.1")
@kotlin.internal.InlineOnly
public inline fun <K, V> mutableMapOf(): MutableMap<K, V> = LinkedHashMap()
It says in the comment that.Casey Brooks
11/05/2019, 5:51 PM