package afternoon.demo02;
import java.util.HashMap;
import java.util.Map;
public class Demo02 {
public static void main(String[] args) {
// 字符串 dhoisddoifhnvsbfiywey
// 找到 有多少字母分别是什么,每个字母出现过多少次
// 字符串 abcdccd
// 一共4个字母 a1 b1 c3 d2
Map<String, Integer> count = new HashMap<String, Integer>();
String word = "adhoisddoifhnvsbfiywey";
char[] c = word.toCharArray();
//遍历
for (Character d : c) {
//判断d数组之前又没有存在map里面,没有的话count.put(d.toString(), 1);添加键和值
//如果有,先用键取出值,在原来得值上+1;
if(count.containsKey(d.toString())) {
//获得键的值
int source = count.get(d.toString());
//原来的值+1;
count.put(d.toString(), source+1);
}else {
count.put(d.toString(), 1);
}
}
System.out.println(count);
}
}