How to compare two maps by their values
Posted
by lewap
on Stack Overflow
See other posts from Stack Overflow
or by lewap
Published on 2010-04-20T09:44:05Z
Indexed on
2010/04/20
9:53 UTC
Read the original article
Hit count: 346
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
© Stack Overflow or respective owner