I need to very efficiently compare two maps in Clojure/Java, and return the difference as determined by Java\'s .equals(..), with nil/null equivalent to \"not present\".
Use the built-in collections API:
Set<Map.Entry<K,V>> difference = a.entrySet().removeAll(b.entrySet());
If you need to convert that back into a map, you must iterate. In that case, I suggest:
Map<K,V> result = new HashMap<K,V>(Math.max(a.size()), b.size()));
Set<Map.Entry<K,V>> filter = b.entrySet();
for( Map.Entry<K,V> entry : a.entrySet ) {
if( !filter.contains( entry ) {
result.put(entry.getKey(), entry.getValue());
}
}