import java.util.*;
public class demo {
public static void main(String args[]) throws Exception{
HashMap<Character,Integer> map = new HashMap<Character,Integer>();
String s = "abcdefgabc";
for(int i = 0; i < s.length(); i++){
char c = s.charAt(i);
Integer val = map.get(new Character(c));
if(val != null){
map.put(c, new Integer(val + 1));
}else{
map.put(c,1);
}
}
printMap(map);
}
private static void printMap(Map map){ // 打印统计信息
Iterator it=map.entrySet().iterator();
while(it.hasNext()){
Map.Entry pair=(Map.Entry)it.next();
System.out.println(pair.getKey() + " = " + pair.getValue());
}
}
}
温馨提示:答案为网友推荐,仅供参考