20190330のKotlinに関する記事は1件です。

Kotlinで要素の出現回数のカウント

gropingBy + eachCountで実現。

listOf(1, 2, 3, 1, 1, 2).groupingBy { it }.eachCount()
=> {1=3, 2=2, 3=1}

eachCountのリファレンスが詳しい。
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/each-count.html

  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む