キー基準でグループ化したMapを返します。
構文
collection.groupBy { keySelector }使用例
下記の値を入力するとサンプルに即時反映されます。
val→words→listOf→grouped→groupBy→it→println→apple→ant→banana→cherry→cat→val words = listOf("apple", "ant", "banana", "cherry", "cat")
val grouped = words.groupBy { it.first() }
println(grouped) // {a=[apple, ant], b=[banana], c=[cherry, cat]}