给定一个字符串列表List<String> strList, 统计里面每一个字符串的出现次数。
如:
{"aa", "aa", "b"}
输出:
{"aa", 2}, {"b", 1}
补充完整下面的方法:
public Map<String, Integer> calStringArray(List<String> strList) {
}
public Map<String,Integer> calStringArray(List<String> strList){
Map<String,Integer> reult=null;
if(strList!=null){
reult=new HashMap<>();
for (String s : strList) {
Integer count = reult.get(s);
if(count==null){
count=1;
}else{
count++;
}
reult.put(s,count);
}
}
return reult;
}
05-12
2732
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
03-03
936
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
03-23
1713
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)