How to compare the values in both hash maps with the help of keys ? Since the keys are identical whereas values are\'nt. and return boolean result for each key comparision. like
Assuming that you have the same entry sets:
import java.util.HashMap;
import java.util.Map.Entry;
public class HashMapComparison {
public static void main(String[] args) {
HashMap map1 = new HashMap();
map1.put(1, "res");
map1.put(2, "tr");
HashMap map2 = new HashMap();
map2.put(1, "res");
map2.put(2, "cd");
for (Entry entry : map1.entrySet()) {
Integer key = entry.getKey();
System.out.println("key " + key + ": "
+ entry.getValue().equals(map2.get(key)));
}
}
}