package com.atguigu.Demo;
import java.util.*;
public class Count {
public static void main(String[] args) {
String s =“qqerrewqwwerrewqweeewqrw”;
HashMap<Character,Integer> map =new HashMap<>();
for (int i=0;i<s.length();i++) {
Character c =s.charAt(i);
Integer total =map.get©;
if (total==null){
map.put(c,1);
}else {
map.put(c,total+1);
}
}
Set<Map.Entry<Character,Integer>> set =map.entrySet();
int max =-1;
for (Map.Entry<Character,Integer> entry:set) {
System.out.println(entry);
max=entry.getValue()>max?entry.getValue():max;
}
for (Map.Entry<Character,Integer> entry:set) {
if (entry.getValue()==max){
System.out.println(“最大值:”+entry.getKey()+" 次数:"+max);
}
}
}
}