What is the smartest way to copy a Map in Kotlin? -
i'd new instance of map same content map doesn't have built-in copy method. can this:
val newinst = somemap.map { it.topair() }.tomap() but looks rather ugly. there more smarter way this?
just use hashmap constructor:
val original = hashmapof(1 "x") val copy = hashmap(original) update kotlin 1.1:
since kotlin 1.1, extension functions map.tomap , map.tomutablemap create copies.
Comments
Post a Comment