title: Is there a set which determines duplicates based on objects' references?
body: <p>I'm trying to find a collection which won't store multiple instances of the same object, but will store identical objects with distinct references.</p>
  <p>For example, the code:</p>
  <pre><code>import java.awt.Rectangle;
  import java.util.HashSet;
  
  public class setTest {
      public static void main(String[] args) {
          Rectangle r1 = new Rectangle();
          Rectangle r2 = new Rectangle();
          HashSet&lt;Rectangle&gt; set = new HashSet&lt;&gt;();
  
          System.out.println(&quot;Add r1      : &quot; + set.add(r1));
          System.out.println(&quot;Contains r2 : &quot; + set.contains(r2));
          System.out.println(&quot;Add r2      : &quot; + set.add(r2));
          System.out.println();
  
          r2.grow(100,100);
          System.out.println(&quot;Grow r2&quot;);
          System.out.println(&quot;Contains r2 : &quot; + set.contains(r2));
          System.out.println(&quot;Add r2      : &quot; + set.add(r2));
          System.out.println(&quot;Contains r2 : &quot; + set.contains(r2));
          System.out.println();
  
          r2.grow(100,100);
          System.out.println(&quot;Grow r2&quot;);
          System.out.println(&quot;Contains r2 : &quot; + set.contains(r2));
      }
  }
  
  </code></pre>
  <p>produces the result:</p>
  <pre><code>Add r1      : true
  Contains r2 : true
  Add r2      : false
  
  Grow r2
  Contains r2 : false
  Add r2      : true
  Contains r2 : true
  
  Grow r2
  Contains r2 : false
  </code></pre>
  <p>Whereas I would like an implementation which produces:</p>
  <pre><code>Add r1      : true
  Contains r2 : false
  Add r2      : true
  
  Grow r2
  Contains r2 : true
  Add r2      : false
  Contains r2 : true
  
  Grow r2
  Contains r2 : true
  </code></pre>
  <p>Does something like that exist? Or would I need to create a collection like that myself?</p>