Sort Map in reverse order in Kotlin
It is a bit late but hope this help.
for API <= 23
map.asIterable().reversed()
for API > 24
map.toSortedMap(Comparator.reverseOrder())
As @Venkata Raju said in the comment, you can use java.util.Comparator.reverseOrder()
for this (available since 1.8):
map.toSortedMap(Comparator.reverseOrder())
You can also use the reverseOrder()
function from the Kotlin standard library's kotlin.comparisons
package:
map.toSortedMap(reverseOrder())