package MapTest;
import java.util.HashMap;
public class MapTest {
public static void Count(String str)
{
char[] chars=str.toCharArray();
HashMap<Character,Integer> hm=new HashMap();
for(char c : chars)
{
if(!hm.containsKey(c))
{
hm.put(c, 1);
}
else
{
hm.put(c, hm.get(c)+1);
}
for(Character key: hm.keySet()){
//hm.keySet()代表所有键的集合,进行格式化输出
System.out.println(key + "====" + hm.get(key));
}
}
}
public static void main(String[] args) {
// TODO 自动生成的方法存根
String str = "abcaaaefdabbhg";
Count(str);
}
}