String input = "bcdefdsjafhakhgdka";
char[] arr = input.toCharArray();//转为字符数组
Map<Character,Integer> map = new HashMap<Character,Integer>();
for(char c : arr) {//将数组存到map中
if(map.containsKey(c)) {
map.put(c, map.get(c)+1);
}else {
map.put(c, 1);
}
}
Set<Entry<Character,Integer>> entrySet = map.entrySet();
int max = 0;
Character cha = 0;
for(Entry<Character,Integer> entry : entrySet) {//遍历map并寻找到出现次数最多的字符
System.out.println(entry.getKey()+"==="+entry.getValue());
if(entry.getValue()>max) {
max = entry.getValue();
cha = entry.getKey();
}
}
System.out.println("max"+max+"==="+cha);