这个问题前几天就有人问过了啊,你们是不是一个学校的啊,是老师留的作业题吧?
下边是我的解答,可以处理有重复的数组(字符串也一样,我给放一块重载写了):public class Test { /**
 * @param args
 */
public static void main(String[] args) {
// TODO Auto-generated method stub

int[] a = new int[] {
0, 1, 2, 3, 3, 3, 4, 4, 4, 2, 5
};

String str = "01233344425";

Map<Integer, Integer> map = web(a);

System.out.println(map);

Map<String, Integer> map1 = web(str);

System.out.println(map1);

}

public static Map<Integer, Integer> web(int[] a) {

Map<Integer, Integer> map = new HashMap<Integer, Integer>();

for (int i = 0; i < a.length; i++) {
if (map.containsKey(a[i])) {
int count = map.get(a[i]).intValue();
map.put(a[i], ++count);
} else {
map.put(a[i], 1);
}
}

Set entrySets = map.entrySet();

int maxValue = 0;

Iterator it = entrySets.iterator();
if (it.hasNext()) {
Entry en = (Entry)it.next();
maxValue = (Integer) en.getValue();
}

while (it.hasNext()) {
Entry en = (Entry)it.next();
int newValue = (Integer) en.getValue();
if (newValue > maxValue) {
maxValue = newValue;

}

Map<Integer, Integer> newMap = new HashMap<Integer, Integer>();

Set<Integer> keySet = (Set<Integer>)map.keySet();
for (Integer key : keySet) {
if (map.get(key) == maxValue) {
newMap.put(key, maxValue);
}
}

return newMap;

}

public static Map<String, Integer> web(String str) {

Map<String, Integer> map = new HashMap<String, Integer>();

for (int i = 0; i < str.length(); i++) {
String tempStr = "" + str.charAt(i);
if (map.containsKey(tempStr)) {
int count = map.get(tempStr).intValue();
map.put(tempStr, ++count);
} else {
map.put(tempStr, 1);
}
}

Set entrySets = map.entrySet();

int maxValue = 0;

Iterator it = entrySets.iterator();
if (it.hasNext()) {
Entry en = (Entry)it.next();
maxValue = (Integer) en.getValue();
}

while (it.hasNext()) {
Entry en = (Entry)it.next();
int newValue = (Integer) en.getValue();
if (newValue > maxValue) {
maxValue = newValue;

}

Map<String, Integer> newMap = new HashMap<String, Integer>();

Set<String> keySet = (Set<String>)map.keySet();
for (String key : keySet) {
if (map.get(key) == maxValue) {
newMap.put(key, maxValue);
}
}

return newMap;

}} 输出结果是一致的:
{3=3, 4=3}
{3=3, 4=3}