title: Why doesn't java.util.HashSet have a get(Object o) method?
body: <p>I've seen other questions about getting objects from <code>Set</code>'s based on index value and I understand why that is not possible. But I haven't been able to find a good explanation for why a get by object is not allowed so thought I would ask.</p>
  
  <p><code>HashSet</code> is backed by a <code>HashMap</code> so getting an object from it should be pretty straightforward. As it is now, it appears I would have to iterate over each item in the <code>HashSet</code> and test for equality which seems unnecessary.</p>
  
  <p>I could just use a <code>Map</code> but I have no need for a key:value pair, I just need a <code>Set</code>.</p>
  
  <p>For example say I have <code>Foo.java</code>:</p>
  
  <pre><code>package example;
  
  import java.io.Serializable;
  
  public class Foo implements Serializable {
  
      String _id;
      String _description;
  
      public Foo(String id){
          this._id = id
      }
  
      public void setDescription(String description){
          this._description = description;
      }
  
      public String getDescription(){
          return this._description;
      }
  
      public boolean equals(Object obj) {
          //equals code, checks if id's are equal
      }
  
      public int hashCode() {
          //hash code calculation
      }
  
  }
  </code></pre>
  
  <p>and <code>Example.java</code>:</p>
  
  <pre><code>package example;
  
  import java.util.HashSet;
  
  public class Example {
  
      public static void main(String[] args){
          HashSet&lt;Foo&gt; set = new HashSet&lt;Foo&gt;();
  
          Foo foo1 = new Foo("1");
          foo1.setDescription("Number 1");
  
          set.add(foo1);
          set.add(new Foo("2"));
  
          //I want to get the object stored in the Set, so I construct a object that is 'equal' to the one I want.
          Foo theFoo = set.get(new Foo("1")); //Is there a reason this is not allowed?
          System.out.println(theFoo.getDescription); //Should print Number 1
      }
  
  }
  </code></pre>
  
  <p>Is it because the equals method is meant to test for "absolute" equality rather than "logical" equality (in which case <code>contains(Object o)</code> would be sufficient)?</p>