String str = "AAAbcccccc";
char[] ch = str.toCharArray();
Map<Character,Integer> map = new HashMap<>();
for(int i =0 ;i<ch.length;i++){
if(map.containsKey(ch[i])){
map.put(ch[i],map.get(ch[i])+1);
}else{
map.put(ch[i],1);
}
}
String s = "AAAbcccccc";
//字符串转成字符数组
char[] charArray = s.toCharArray();
HashMap<Character, Integer> map = new HashMap<>();
//遍历字符数组
for (char c : charArray) {
//判断map中是否包含字符,如果包含其值加一,如果不包含值等于1
if(map.containsKey(c)) {
map.put(c, map.get(c) + 1);
}else {
map.put(c, 1);
}
}
System.out.println(map);