Skip to content

Instantly share code, notes, and snippets.

@fpdjsns
Last active October 15, 2019 23:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fpdjsns/dd8cc62058254e3c6ddf63f779a2e847 to your computer and use it in GitHub Desktop.
Save fpdjsns/dd8cc62058254e3c6ddf63f779a2e847 to your computer and use it in GitHub Desktop.
Kotlin list.groupBy
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