Is there a way to sort groupBy keys in rx-java/kotlin?

Viewed 1211

Here's an example:

Observable.fromIterable(listOf("4444", "22", "333", "1", "55555"))
    .groupBy { it.hashCode() }
    .subscribe { group ->
        group.toList().subscribe { list -> println("${group.key} $list") }
    }

output:

1600 [22]
49 [1]
50643 [333]
50578165 [55555]
1600768 [4444]

How to sort the keys in ascending/descending order or using a custom sort comparator?

1 Answers
Related