public static void main(String[] args) throws IOException {
int[] arr = {1,4,1,4,2,5,4,5,8,7,8,77,88,5,4,9,6,2,4,1,5};
HashMap<Integer, Integer> map = new HashMap();
for(int i:arr){
//返回指定的键被映射到的值,或者如果该映射不包含该键的映射,则返回NULL
Integer integer = map.get(i);
if(integer == null){
map.put(i, 1);
}else{
map.put(i, map.get(i)+1);
}
}
Set<Entry<Integer, Integer>> set = map.entrySet();
for(Entry<Integer, Integer> entry:set){
System.out.println(entry.getKey()+"出现:"+entry.getValue());
}
}