associateBy
Returns a Map containing the characters from the given char sequence indexed by the key returned from keySelector function applied to each character.
inline fun <K> CharSequence.associateBy(keySelector: (Char) -> K): Map<K, Char>(source)
val text = "Kotlin"
val charMap: Map<Int, Char> = text.associateBy { it.code }
// Example output:
// {75=K, 111=o, 116=t, 108=l, 105=i, 110=n}