Question: a method named characterCounts that takes a String and returns back a map of counts of the number of times each character appears in the
a method named characterCounts that takes a String and returns back a map of counts of the number of times each character appears in the String. Your solution can ONLY use Map and String methods.
For example, after the following code segment:
// str is "abcbadebdd" Map counts = characterCounts(str);
Should set the value of counts to be:
// counts is a map containing { ('a', 2), ('c', 1), ('d', 3), ('b', 3), ('e',1) }/* Return a map of counts of the characters in a string * * @param str String to count chars in * @return map containing the counts of the chars in str */ public static Map characterCounts(String str) { // TODO: Your code below this line }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
