我有班级中的学生成绩地图,我想按成绩进行计数,可以通过迭代值然后增加地图中的计数来完成,是否有更好的使用 Streams 的方法。
Map<String, String> grades = new HashMap();
grades.put("100", "A");
grades.put("101", "B");
grades.put("102", "A");
grades.put("103", "C");
grades.put("104", "D");
grades.put("105", "B");
grades.put("106", "B");
grades.put("107", "C");
Run Code Online (Sandbox Code Playgroud)
我的输出映射应该有 A=2、B=3、C=2、D=1