Java统计List集合中每个元素出现的次数

public static Map<String,Integer> frequencyOfListElements( List items ) {
if (items == null || items.size() == 0) return null;
Map<String, Integer> map = new HashMap<String, Integer>();
for (String temp : items) {
Integer count = map.get(temp);
map.put(temp, (count == null) ? 1 : count + 1);
}
return map;
}

posted @ 2021-11-09 22:45  learning豪  阅读(2074)  评论(0编辑  收藏  举报