logo CodeStepByStep logo

split

Language/Type: Java collections Map
Related Links:

Write a method named split that accepts a Set of strings as a parameter and 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 representing string lengths, and whose values are sets of strings of that length. Within each set in your result, the strings should be sorted in alphabetical order. For example, if a variable called words contains the following set of strings:

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

Then the call of split(words) should return the following map:

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

Do not modify the set passed in as the parameter.

Method: Write a Java method as described, not a complete program or class.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.