// ① 请统计出其中每一个字母出现的次数,在控制台打印如下的格式:
// A—-3
// B—-4
// C—-1
// D—-2
给大家分享一下String str=\"QWERTYUIQQQWJHDAADADBBBBCAD\";char[] charArray = str.toCharArray();HashMap<Object, Integer> hashMap = new HashMap<>();ArrayList<Object> arrayList2 = new ArrayList<Object>();//遍历字符数组for (int j = 0; j < charArray.length; j++) {//使用collections工具类将字符数组添加到集合里面Collections.addAll(arrayList2, charArray[j]);//使用方法获取到每个字母的次数int frequency = Collections.frequency(arrayList2, arrayList2.get(j));//分别将字符和次数个数添加到hashmap的键和值里面hashMap.put(charArray[j],frequency );}//获取到hashmap的entry键值对Set<Entry<Object, Integer>> entrySet = hashMap.entrySet();//遍历获取,拼接格式for (Entry<Object, Integer> entry : entrySet) {System.out.println(entry.getKey()+\"------\"+entry.getValue());}System.out.println(\"=============最大的值=================\");Integer max=0;for (Entry<Object, Integer> entry : entrySet) {if (max<=entry.getValue()) {max=entry.getValue();System.out.println(entry.getKey()+\"---\"+ max);}}