Section Lists to Map
Write a method called sectionListsToMap
that, given a List
of String
s, parses it into a
Map<String, Set<String>>
as follows.
Each String
in the passed list contains a comma-separated list of names of people in a discussion section.
The first name is the section leader, and the rest are students.
Your map should map each section leader to the set of students in their section.
No section leader or student will appear twice in the data set.
For example, given the String
s "challen,student1", "ruisong4,student2, student3" and "friendly,student4, student5",
your map would have keys "challen", "ruisong4", and "friendly".
"challen" would map to a set containing "student1", "ruisong4" would map to a set containing "student2" and
"student3", and so on.
You should assert that the passed String
is not null
, but if it is not null
it will have the format
described above.
A few hints for approaching this problem.
First, consider how to use .split
and .trim
appropriately to parse the input String
.
You should get this part to work before proceeding.
Then consider when you need to create the map and each set, and how to populate them.
The imports java.util.Map
, java.util.Set
, java.util.HashMap
, and java.util.HashSet
are already provided
for you.
You should not need additional import
statements to complete this problem.