Map<Character, Integer> getMap(String target) {
return target.chars().boxed()
.map(c -> Character.valueOf((char) c.intValue()))
.collect(Collectors.groupingBy(
c -> c,
Collectors.reducing(0, c -> 1, Integer::sum)
));
}
Run Code Online (Sandbox Code Playgroud)
这条线target.chars().boxed().map(c -> Character.valueOf((char) c.intValue()))真的很难看,有没有更好的方法呢?