Bulk operations on sets/ map problem
Quote:
• For each band stored in allBands create an entry in bandFans with the band
name as key and a new empty set as its value.
• For each person in allPeople
o For each band in that person’s personInterests
add the person to the set which is the value of that band in
bandFans.
The first two points are working okay (I think) but I just can't seem to figure out how to add the all names into the set (only one currently). This is my code so far:
Code :
public void workOutBandFans()
{
Set<String>peopleSet = new HashSet<String>();
for (String band : allBands)
{
bandFans.put(band, new HashSet<String>());
}
for (String person : allPeople)
{
for (String band : personInterests.get(person))
{
peopleSet.add(person);
bandFans.put(band, peopleSet);
}
peopleSet = new HashSet<String>();
}