public class Test {
public static void main(String[] args) throws IOException {
String str = "abcdekka27qoq";
char[] cs = str.toCharArray();
HashMap<Character, Integer> hashMap = new HashMap<>();
for (char c : cs) {
Integer value = hashMap.get(c);
if(value == null){
hashMap.put(c, 1);
}else{
hashMap.put(c, value+1);
}
}
//遍历集合
String msg = "";
for (Entry<Character, Integer> c : hashMap.entrySet()) {
System.out.print(c.getKey()+"("+c.getValue()+")"+" ");
msg += c.getKey()+"("+c.getValue()+")"+" ";
}
}
}