<Sorted map with custom comparator> I want to crea...
# stackoverflow
u
Sorted map with custom comparator I want to create a sorted map with a composite key. If it didn't need to be sorted, I would use val myMap = mapOf( Pair(1,"a") to "A", Pair(2,"a") to "AA", Pair(1,"b") to "B" ) But it has to be a sorted map and this doesn't work: val myMap = sortedMapOf( Pair(1,"a") to "A", Pair(2,"a") to "AA", Pair(1,"b") to "B" ) What's the most idiomatic way to create a sorted map with a custom comparator? I want it to compare by the first element of the pair and then by the second.