Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 1 of 1

Thread: Bulk operations on sets/ map problem

  1. #1
    Junior Member
    Join Date
    Dec 2009
    My Mood
    Thanked 0 Times in 0 Posts

    Default Bulk operations on sets/ map problem

    • 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
    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:
       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))
                bandFans.put(band, peopleSet);
             peopleSet = new HashSet<String>();
    Last edited by kyuss; March 15th, 2010 at 05:54 AM.

Similar Threads

  1. [SOLVED] Maps and adding to sets as values
    By mds1256 in forum Collections and Generics
    Replies: 3
    Last Post: March 26th, 2010, 09:12 AM
  2. [SOLVED] Sets and creating a new set containing a common number
    By mds1256 in forum Collections and Generics
    Replies: 2
    Last Post: February 26th, 2010, 06:00 PM
  3. Lists of Sets and Sets of Lists
    By Newoor in forum Collections and Generics
    Replies: 2
    Last Post: December 8th, 2009, 08:13 PM