java8 stream统计字符串中每个字母的个数

String str="qqqweaaaasdffg";
HashMap<String, Long> collect = Stream.of(str.split("")).collect(Collectors.groupingBy(Function.identity(), HashMap::new, Collectors.counting()));
collect.entrySet().forEach(e->{
System.out.println(e.getKey()+"============"+e.getValue());
});
posted @ 2021-08-19 16:01  冬冬20191024  阅读(478)  评论(0)    收藏  举报