String[] a = {"a","b","c","d","a"};
HashMap<String, Integer> map = new HashMap<>();
for (int i = 0; i < a.length; i++) {
if(map.get(a[i])!=null){
map.put(a[i],map.get(a[i])+1);
}else {
map.put(a[i],1);
}
map.forEach((key,value)->{
if(value>1)
System.out.println("数组中重复元素的个数: " + key +" = "+value);
});
}
查找数组中重复元素的个数(Map)
最新推荐文章于 2023-03-24 15:36:45 发布