Kotlin 2 · Collections and lambdas
Group, sort and count
Group items by a key, sort them and count matches.
val byLength = names.groupBy { it.length }
val sorted = names.sortedByDescending { it.length }
val count = names.count { it.startsWith("G") }
Official Kotlin 2 documentation