尧叔
public static void main(String[] args) {
String s = "snakeasdfasdfagdsafas";
char[] chars = s.toCharArray();
Map<Character, Integer> map = new HashMap<Character, Integer>();
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<Character, Integer> characterIntegerEntry : map.entrySet()) {
System.out.println(characterIntegerEntry.getKey() + "出现"
+ characterIntegerEntry.getValue() + "次");
}
}谢谢采纳!