public static String replace1(String text) {
HashMap<String,Integer> hm=new HashMap<>();
String s;//用来得到字符串中出现的字符
int max=0;//记录重复字符的最大重复次数
int num=0;//记录重复字符的重复次数
for (int i = 0; i < text.length(); i++) {
s=String.valueOf(text.charAt(i));
for (int j = 0; j <text.length(); j++) {
if(String.valueOf(text.charAt(j)).equals(s)) {
num++;//记录重复字符的重复次数
}
}
hm.put(s,num);//用map集合储存字符,字符出现的次数
if(num>max)
max=num;
num=0;
}
String ss="";//最终返回的字符,重复次数。
for (String str : hm.keySet()) {
if(hm.get(str)==max)//遍历map的键(字符),如果对应的值为最大重复次数就是要找的字符
ss+="["+str+","+max+"]";//次数最多的字母有多个,则全部求出)
}
return ss;
}