title: If key in hashtable is a class object, how does containsKey work?
body: <p>When we put a class Object (that has say three data members) in a hashtable, how can I prevent putting another entry into the hash table whose key has the same three data members ? Cos I am guessing this will be a new object. So hashtable.containsKey() will return false even when there is a key (this class object) that has the very same data members as the one that is waiting to be inserted. </p>
  
  <p>More clearly:
  I have a class like</p>
  
  <pre><code>class Triplet {
  private Curr curr;
  private Prev prev;
  private Next next;
  }
  </code></pre>
  
  <p>I have a hashtable structure like:</p>
  
  <pre><code>Hashtable&lt;Triplet, Integer&gt; table = new Hashtable&lt;Triplet, Integer&gt;();
  </code></pre>
  
  <p>When I do:</p>
  
  <pre><code>if(!table.containsKey(triplet_to_inserted))
  table.put(triplet, new Integer(0));
  </code></pre>
  
  <p>will this insert a duplicate even if the table contains a triplet that already has the same data members ? That is: triplet_to_be_inserted.curr, triplet_to_be_inserted.next and triplet_to_be_inserted.prev
  If yes, how to prevent this ? </p>
  
  <p>Also, for any entry to be inserted, will containsKey() ever return true at all ? 
  How to work around this problem ?</p>
  
  <p>Thanks.</p>