the code below is counting character. I am a bit new to hashmaps so I am confused about the syntax and what's it doing from this line: Map charCounter = new TreeMap(); Can someone please dumb this code down and explain from that line please?
public class repeated {
public static void main(String[] args) {
String str = "Abaa";
char[] char_array = str.toCharArray();
System.out.println("The Given String is : " + str);
Map<Character, Integer> charCounter = new TreeMap<Character, Integer>();
for (char x : char_array) {
charCounter.put(x,charCounter.get(x) == null ? 1 : charCounter.get(x) + 1);
}
for (Character key : charCounter.keySet()) {
System.out.println("occurrence of '" + key + "' is "+ charCounter.get(key));
}
}
}