Results 1 to 4 of 4
- 02-08-2011, 02:26 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 2
- Rep Power
- 0
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!
- 02-08-2011, 02:53 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Do you know how to traverse through a map?
- 02-08-2011, 12:12 PM #3
Member
- Join Date
- Feb 2011
- Posts
- 2
- Rep Power
- 0
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!
- 02-09-2011, 12:23 PM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Why don't you keep the records in a separate ArrayList?
Similar Threads
-
Help with Maps
By snripa in forum New To JavaReplies: 4Last Post: 12-14-2010, 09:27 AM -
How to iterate through two Arrays?
By aRTx in forum Advanced JavaReplies: 3Last Post: 05-18-2010, 07:48 AM -
Maps
By natep67 in forum New To JavaReplies: 8Last Post: 05-06-2009, 03:59 AM -
Iterate Text File
By Boaz in forum New To JavaReplies: 5Last Post: 03-17-2009, 08:55 AM -
iterate HashMap with logic
By Heather in forum Web FrameworksReplies: 2Last Post: 07-03-2007, 09:47 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks