I would like to print the occurrence of each character in a text using a dictionary system:
Ex: Text is "I like apples"
Console output looks like:
'i' has an occurrence of 2 times on positions: 1, 4
'l' has an occurrence of 2 times on positions: 3, 11
..
So far I've got this
String text = "text";
HashMap<Integer, String> dictionary = new HashMap<Integer, String>();
for (int i = 0; i < text.length(); i++) {
dictionary.put(i, String.valueOf(text.charAt(i)));
}
Basically just adding each letter to a key value in the dictionary, but I can't figure out how to do the print...