how to count occurrences of each character in a String