/**
* 计算数组里面字符出现的次数
*/
public class Demo5 {
public static void main(String[] args) {
String str= "woaiwodezuguo";
char[] chars= str.toCharArray();
Map<String, Integer> map = new LinkedHashMap<>();
for (char cr : chars) {
Integer num = map.get(cr + "");
if (num == null){
num=0;
}
map.put(cr+"",++num);
}
System.out.println(map);
}
}
==============================================
输出结果:
{w=2, o=3, a=1, i=1, d=1, e=1, z=1, u=2, g=1}