public static void main(String[] args) {
String s = "snakeasdfasdfagdsafas";
char[] chars = s.toCharArray();
Map map = new HashMap();
for (char aChar : chars) {
if (!map.containsKey(aChar)) {
map.put(aChar, 1);
}else {
Integer i = map.get(aChar);
i++;
map.put(aChar, i);
}
}
for (Map.Entry characterIntegerEntry : map.entrySet()) {
System.out.println(characterIntegerEntry.getKey() + "出现"
+ characterIntegerEntry.getValue() + "次");
}
}
谢谢采纳!