public static void main(String[] args) {
Map<Character, Integer> data = new HashMap<Character, Integer>();
String s = "aaaab";
char[] chars = s.toCharArray();
for (char a : chars) {
if (data.containsKey(a)) {
int value = data.get(a);
data.put(a, value + 1);
} else {
data.put(a, 1);
}
}
Iterator it = data.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pairs = (Map.Entry) it.next();
System.out.println(pairs.getKey() + " = " + pairs.getValue());
}
}