求大神回答,用集合框架求字符串中的各个字符的数量

用集合框架求字符串中的各个字符的数量,例如String ="abbbffafzz";

http://blog.csdn.net/hoho_12/article/details/51220948

用HashMap,如果存在就累加一,不存在就存入,值为1.参考:

 Map<Char,Integer> countMap = new HashMap<Char,Integer>();
String str="abbbffafzz";
for(int i=0;i<str.length;i++){
 char c = str.charAt(i);
 if(countMap.contains(c)){
    countMap.put(c,countMap.get(c));
 }else{``
 Map<Char,Integer> countMap = new HashMap<Char,Integer>();
String str="abbbffafzz";
for(int i=0;i<str.length;i++){
 char c = str.charAt(i);
 if(countMap.contains(c)){
    countMap.put(c,countMap.get(c));
 }else{
 countMap.put(c,1);
 }
 }