public class test {
public static void main(String[] args) {
int a[] = { 1, 4, 2, 1, 5, 1, 8, 1, 1 };
// 第一个值为出现的数字,第二个值是出现的次数
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
for (int i = 0; i < a.length; i++) {
if (map.containsKey(a[i])) {
int temp = map.get(a[i]);
map.put(a[i], temp + 1);
} else {
map.put(a[i], 1);
}
}
Collection<Integer> count = map.values();
Integer max = Collections.max(count);
for (Integer integer : map.keySet()) {
if (map.get(integer) == max) {
System.out.println("次数最多的是" + integer + " " + "次数为" + map.get(integer));
}
}
}
}