import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Set;
public class MainClass {
public static void main(String[] args) {
String str = "Hell? ow!orld";
str = str.replaceAll("[^a-zA-Z]", "");
HashMap<Character,Integer> map = new HashMap<Character,Integer>();
for(Character c : str.toCharArray()) {
if(map.containsKey(c)) {
map.replace(c, (int)map.get(c)+1);
}
else {
map.put(c, 1);
}
}
//map 的entry遍历方法
for(Entry<Character, Integer> en : map.entrySet()){
System.out.println(en.getKey() +":"+ en.getValue());
}
//map 的set遍历方法
Set set = map.keySet();
for(Object key : set) {
System.out.println(key +":"+map.get(key));
}
//map 的foreach遍历方法
map.forEach((key,value)->{
System.out.println(key +":"+value);
});
}
}