GroupBy

This groups the elements into a Key-Value Map. The Key is the result of the selector function, and the value is the list of all the elements that satisfy the selector function condition:

val strings = listOf("abc", "ade", "bce", "bef")
val groupped = strings.groupBy { s -> s[0] }

We grouped here by the first character of the string, and now the grouped map looks like this [“a” : [“abc”, “ade”], “b” : [“bce”, “bef”].

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.225.188