In order to sort in decreasing order, just reverse the order of Comparator using Collections. reverseOrder() or Comparator. reverse() method of Java 8.
To sort an Array in descending order in Kotlin, use Array. sortDescending() method. This method sorts the calling array in descending order in-place. To return the sorted array and not modify the original array, use Array.
Yes, it will. The reference for mutableMapOf() says: The returned map preserves the entry iteration order. This is exactly the property that you asked about.
I have val myHashMap = HashMap<String, MutableList<TestItem>>()
, hashmap key value is formatted date as a string for example 20-06-2018
how can I sort this hashMap in descending order?
expected result:
22-06-2018 : []
21-06-2018 : []
20-06-2018 : []
I use this code to sort it, but result is in ascending order:
val sortedMap = myHashMap.toSortedMap(compareBy { it })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With