i’d like to take a `HashMap` and sort it by its ke...
# getting-started
m
i’d like to take a
HashMap
and sort it by its keys, but i only really care about having a specific key at the beginning, the rest of them don’t matter. something like
Copy code
val myHashMap = HashMap<String, Int>
myHashMap.put("hello", 0)
myHashMap.put("world", 1)
val sorted = myHashMap.toSortedMap(compareBy { it == "world" })
can anyone help me figure out how to do that?
d
Are you sure it's a map you need? Otherwise
LinkedHashMap
will do the trick.
o
val hashMap: SortedMap<String, Int> = sortedMapOf()