title: HashMap with object value as key
body: <p>Say I have 2 lists of Nodes (Node is some comparable object, the details don't matter). I'd like to find which Nodes appear on both lists - not necessarily the same Node object, but Nodes whose compareTo returns 0.</p>
  
  <p>For example, nodeA is on list A and nodeB is on list B. They are NOT the same Node but nodeA.compareTo(nodeB) will return 0 (equality).</p>
  
  <p>I'd like to solve this by iterating over list A and putting the nodes in a HashMap/HashSet, then iterating over list B and checking which nodes have already been inserted into the HashMap/HashSet. The issue is, this will not work as the Nodes will not be considered equal by the HashMap unless they are the same actual Node.</p>
  
  <p>How can I solve this problem? Note that I am <strong>not</strong> looking for other solutions to this problem, but for an understanding of if (and how) I can use a HashMap, HashSet or another similar data structure in the given example scenario.</p>