Simple as this:
String s = "aabbcd"; Map<Character, Integer> map = new HashMap<>(); for (var c: s.toCharArray()){ map.put(c, (int)Arrays.stream(s.chars().toArray()).filter((i)->i == c).count()); }
Output: {a=2, b=2, c=1, d=1}