Hi guys, I've a question: I want to convert a stri...
# getting-started
a
Hi guys, I've a question: I want to convert a string(say, origin_source = sources) to mutableMap. How to implement with
associateTo
?
s
do you want to convert the string itself to a map or a collection of strings
a
string itself
d
Into a map of what?
a
mutableMapOf<String, String>
k
Can you give a complete input/output example?
👆 2
i
If you have a list of strings in form of
a=b
and you want to split each string by
=
into key and value, you can do it as following:
Copy code
list.associateTo(mutableMap) { it.split("=").let { (key, value) -> key to value } }
a
Thanks @ilya.gorbunov
💤 1