title: Removing a user defined object in a HashSet in Java
body: <p>I have created a simple class called Idea with a HashSet of ColumnPositions(another class I created with just an x and y field) . The equals and hashcode method in ColumnPosition looks like this:</p>
  
  <pre><code>@Override
  public int hashCode() {
      final int prime = 31;
      int result = 1;
      result = prime * result + x;
      result = prime * result + y;
      System.out.println("hashCode: " + result);
      return result;
  }
  
  @Override
  public boolean equals(Object obj) {
      if (obj instanceof ColumnPosition) {
          ColumnPosition cp = (ColumnPosition) obj;
          if (cp.x != this.x || cp.y != this.y) {
              return false;
          }
      }
      return true;
  }
  </code></pre>
  
  <p>However, when I go to test the Idea class and try to remove a ColumnPosition object within the HashSet of the Idea object. It doesn't work. What's wrong?? Thanks!</p>
  
  <pre><code>public void test_HashSetRemoveColumnPosition() {
      ColumnPosition column_03 = new ColumnPosition(0, 3);
  
      Set&lt;ColumnPosition&gt; columns = new HashSet&lt;ColumnPosition&gt;();
      columns.add(column_03);
  
      this.idea.getColumnPositions().add(column_03);
      assertEquals(1, columns.size());
  
      assertTrue(this.idea.getColumnPositions().remove(column_03)); // this is passing
      assertEquals(0, columns.size()); // this is failing because columns.size() still equals 1. WHAT?! How is this possible if the remove method returned true?
  }
  </code></pre>