Map<Character, Long> frequency = str.chars() .mapToObj(c -> (char)c) .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));