notes/pl/kt/features/collection/grouping.txt
ihar_hancharenka f78cdbe9b8 m
2025-09-24 18:08:45 +03:00

12 строки
463 B
Plaintext

https://kotlinlang.org/docs/collection-grouping.html
https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-grouping/
groupBy(keySelector),
groupingBy(...)
.eachCount()
https://www.slingacademy.com/article/kotlin-grouping-and-counting-elements-in-maps/
val items = listOf("apple", "banana", "carrot", "apple", "carrot")
val grouped = items.groupingBy { it.first() }.eachCount()
println(grouped) // Output: {a=2, b=1, c=2}