How to compare two maps by their values? I have two maps containing equal values and want to compare them by their values. Here is an example:
Map a = ne
The correct way to compare maps for value-equality is to:
In other words (minus error handling):
boolean equalMaps(Mapm1, Mapm2) {
if (m1.size() != m2.size())
return false;
for (K key: m1.keySet())
if (!m1.get(key).equals(m2.get(key)))
return false;
return true;
}