How to compare two maps by their values
- by lewap
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 = new HashMap();
a.put("f"+"oo", "bar"+"bar");
a.put("fo"+"o", "bar"+"bar");
Map b = new HashMap();
a.put("f"+"oo", "bar"+"bar");
a.put("fo"+"o", "bar"+"bar");
System.out.println("equals: " + a.equals(b)); // obviously false
.... what to call to obtain a true?
Obviously, to implement a comparison it not difficult, it is enough to compare all keys and their associated values. I don't believe I'm the first one to do this, so there must be already a library functions either in java or in one of the jakarta.commons libraries.
Thanks