Last active
October 15, 2019 23:38
-
-
Save fpdjsns/dd8cc62058254e3c6ddf63f779a2e847 to your computer and use it in GitHub Desktop.
Kotlin list.groupBy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class Member(val no:Long, val name: String) | |
fun main() { | |
val list = listOf(Member(1, "일"), Member(1, "이"), Member(3, "삼")) | |
val result = list.groupBy({it.no}, {it.name}) | |
println(result) // {1=[일, 이], 3=[삼]} | |
println(result[1]) // [일, 이] | |
println(result[2]) // null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment