I need to iterate the hashmap and find list of common elements among all the list available..
What is the best way to handle them
I need to store the common element in a list and remove the common elements from the original list..
I have no clue how to handle this..
any help is highly appreciated..
Joined: Apr 13, 2003
I would suggest that you keep all the elements in one list. Then check if the list contains the value already(a HashSet would be a better option). If it does contain the value copy that element into the common list. Meanwhile carry on the procedure with HashMap it's just that you would not have to iterate through all the pairs.
Joined: Jan 29, 2003
I like to do problems like this in sorted order, a holdover from my days when the data was all on tape with sequential reads only. If you can copy the list data into TreeSets and not mind losing duplicates you might be in business. Yesterday I posted my old favorite Master-Update-Merge algorithm. I have a variation for any number of inputs instead of just two and even built it into a little utility so I never have to write it again. Let me know if that sounds interesting. [ June 28, 2007: Message edited by: Stan James ]
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joined: May 04, 2007
Thanks for the reply. Now I got into a different situation
I have a list of Objects and I am trying to overide the equals method in my object class to check for equality..