groupByTo
Groups elements of the original array by the key returned by the given keySelector function applied to each element and puts to the destination map each group key associated with a list of corresponding elements.
@IgnorableReturnValueinline fun <T, K, M : MutableMap<in K, MutableList<T>>> Array<out T>.groupByTo(destination: M, keySelector: (T) -> K): M(source)
val fruits = arrayOf("apple", "apricot", "banana", "blueberry", "cherry")
val groups = mutableMapOf<Char, MutableList<String>>()
fruits.groupByTo(groups) { it.first() }
println(groups) // {a=[apple, apricot], b=[banana, blueberry], c=[cherry]}