Results 1 to 4 of 4
  1. #1
    metal_pat is offline Member
    Join Date
    Feb 2011
    Posts
    2
    Rep Power
    0

    Default Iterate 2 maps and adding value to each

    Hello, I have 2 maps, One have Park object as key and an empty TreeList of Ride object as value ( parkMap ). The second one have Ride object as key and an empty Treelist of Park as value (rideMap).

    Now for a given Park name and Ride name, I must iterate trough each map ( parkMap for Park and rideMap for Ride ) and if they both exist in their respective map, I must add the Ride to the empty TreeSet of the Park key and the Park to the empty TreeSet of the Ride key.

    I am stuck! Any suggestions??

    Thank you!

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  3. #3
    metal_pat is offline Member
    Join Date
    Feb 2011
    Posts
    2
    Rep Power
    0

    Default

    Yesi I do, sorry, I should have posted what I have coded so far :

    for (Iterator<Park> i = parkMap.keySet().iterator();i.hasNext();)
    if ( i.next().getName.compareTo(parkName)= 1)

    This will tell me if the Park is present in my map. I then do the same in the Ride map to find if the ride is present.

    Now what I don't know is how to put the object I have found in the value ( in my case a TreeSet ).? Can you "put" something in the value at a specific place ( which would be i.next() I guess?? ) ??

    Thank you!

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

Similar Threads

  1. Help with Maps
    By snripa in forum New To Java
    Replies: 4
    Last Post: 12-14-2010, 09:27 AM
  2. How to iterate through two Arrays?
    By aRTx in forum Advanced Java
    Replies: 3
    Last Post: 05-18-2010, 07:48 AM
  3. Maps
    By natep67 in forum New To Java
    Replies: 8
    Last Post: 05-06-2009, 03:59 AM
  4. Iterate Text File
    By Boaz in forum New To Java
    Replies: 5
    Last Post: 03-17-2009, 08:55 AM
  5. iterate HashMap with logic
    By Heather in forum Web Frameworks
    Replies: 2
    Last Post: 07-03-2007, 09:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •