Create a public class CountLetters
providing a single static method countLetters
.
countLetters
accepts an array of String
s and returns a Map
from String
s to Integer
s.
(You can reject null
arguments using assert
.)
The map should contain counts of the passed Strings
based on their first letter.
For example, provided the array {"test", "me", "testing"} your Map
should be {"t": 2, "m": 1}.
You should ignore empty String
s and not include any zero counts.
As a reminder, you can retrieve the first character of a String
as a char
using charAt
.
You may find substring
more helpful.
You may also want to examine the Map
getOrDefault
method.
You can use any Map
implementation in java.util
.
You're challenge is to write tests for this problem described above.
Stuck? You may find these lessons helpful: