mport java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
public class Test {
public static void main(String[] args) {
String str ="aaaabb555555bccd";
HashMap<String, Integer> map = new HashMap<String, Integer>();
for(int i=0; i<str.length(); i++){
String var = String.valueOf(str.charAt(i));
if(!map.containsKey(var)){
map.put(var, 1);
}else{
int aa = map.get(var);
map.put(var, aa+1);
}
}
for(Entry<String, Integer> maps : map.entrySet()){
System.out.println(maps.getKey()+"的个数:"+maps.getValue());
}
//排序数组取得最大值
Collection<Integer> c = map.values();
Object[] obj = c.toArray();
Arrays.sort(obj);
//map通过value找到key
for(Entry<String, Integer> maps : map.entrySet()){
if(obj[obj.length-1].equals(maps.getValue())){
System.out.println(maps.getKey() + "这个字符出现的次数最多,共" + obj[obj.length-1] + "个重复");
}
}
}
}