public static Map<String,Integer> count( 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;
}
对一个list进行统计合并
最新推荐文章于 2025-08-09 16:41:21 发布
本文介绍了一种使用Java HashMap统计List中元素出现频率的方法。通过遍历List并将元素作为键,其出现次数作为值存储在Map中,实现了高效的数据统计。
244

被折叠的 条评论
为什么被折叠?



