Given a String
containing words separated by the " " (space) character, write a method wordLengths
that return a
Map<String, Integer>
mapping each word that is contained in the String
to its length.
assert
that the passed String
is not null
.
So, for example, given the String
"Wow that is amazing", you would return a map with four mappings:
"Wow" to 3, "that" to 4, "is" to 2, and "amazing" to 7.
Note that you should not add any import
statements, since both java.util.Map
and java.util.HashMap
are
already available.
You're challenge is to write tests for this problem described above.
Stuck? You may find these lessons helpful: