two HashMap iteration

Posted by user431276 on Stack Overflow See other posts from Stack Overflow or by user431276
Published on 2010-12-26T04:04:53Z Indexed on 2010/12/26 7:54 UTC
Read the original article Hit count: 203

Filed under:
|

I have two HashMaps and I can iterate both hashmaps with following code

Iterator it = mp.entrySet().iterator();
while (it.hasNext()) {
    Map.Entry pairs = (Map.Entry)it.next();
    String firstVal = pairs.getValue();
}

Iterator it2 = mp2.entrySet().iterator();
while (it2.hasNext()) {
    Map.Entry pairs2 = (Map.Entry)it.next();
    String SecondVal = pairs2.getValue();
}

myFunction(firstVal, SecondVal)

Is there anyway to iterate two hashmaps at the same time without using two loops?

Currently, I have a method that accepts two parameters and each parameter value is stored in first and second hashmap. I have to iterate first hash then second to get values. I think there must be a good way to do it but I don't know :(

P.S: there could be some errors in above code as this is just an example to explain my problem. Each iterator is a method in original program and accept one parameter. I couldn't copy past real time functions as they are HUGE !

© Stack Overflow or respective owner

Related posts about java

Related posts about data-structures