可能重複:
How to count occurrence of an element in a List
Count occurences of word in ArrayList如何從列表中得到重複值(計數)的數量
假設我有一個列表下面的值
emp1, emp2, emp3, emp2, emp1, emp4, emp1
我需要得到的號碼一個字符串重複的次數如下
emp1 - 3 times
emp2 - 2 times
emp3 - 1 times
emp4 - 1 times
我想通過使用map來實現這一點。這是正確的方式還是有更好的方法?