title: HashSet: Cannot Remove An Object That Is Equal?
body: <p>In my code, I am trying to remove an element in a HashSet. I have overridden the equals method in my object.</p>
  
  <pre><code>for (BitVector bv : implicantsToDeleteViaBitVector) {
              System.out.println(bv + " , " + bv.hashCode());
  
              for(BitVector bvSetbv : bvSet){
                  if(bv.equals(bvSetbv)){
                      System.out.println("match " + bv);
                  }else{
                      System.out.println("No match " + bv + "," + bvSetbv);
                  }
              }
  
              if(bvSet.remove(bv)){
                  System.out.println("Remove");
              }else{
                  System.out.println("No match found by remove");
              }
  ...
  </code></pre>
  
  <p>The problem is that my equals method will return true but my remove returns false on the same item being examined. This is the equals method:</p>
  
  <pre><code>@Override
  public boolean equals(Object o) {
      if (this == o)
          return true;
      if (!(o instanceof BitVector))
          return false;
      BitVector v = (BitVector) o;
      boolean sameSize = mySize == v.getSize();
      boolean sameTerms = this.bitVectorList
              .containsAll(v.getBitVectorList());
  
      return (sameSize &amp;&amp; sameTerms);
  }
  </code></pre>
  
  <p>Does remove use the equals() method in a class? If so, then why is this code not working?</p>