logo Practice-It logo

split

Language/Type: Java Collections Sets and Maps
Author: Marty Stepp (on 2020/10/22)

Write a method called split that takes a set of strings as a parameter and that returns the result of splitting the strings into different sets based on the length of the strings. In particular, your method should return a map whose keys are integers and whose values are sets of strings of that length. For example, if a variable called words contains the following set of strings:

[to, be, or, not, that, is, the, question]

then the call split(words) should return a map whose values are sets of strings of equal length and whose keys are the string lengths:

{2=[be, is, or, to], 3=[not, the], 4=[that], 8=[question]}

Notice that strings of length 2 like "be" and "is" appear in a set whose key is 2. If the set had instead stored these strings:

[four, score, and, seven, years, ago, our, fathers, brought, forth]

Then the method would return this map:

{3=[ago, and, our], 4=[four], 5=[forth, score, seven, years], 7=[brought, fathers]}
Type your solution here:


This is a method problem. Write a Java method as described. Do not write a complete program or class; just the method(s) above.

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.