Help us understand the problem. What is going on with this article?

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

More than 1 year has passed since last update.

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

zigenin
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away