title: Java: Removing a custom object from a Vector
body: <p>I have <code>MyClass</code>, which stores two integers, and I have a <code>Vector&lt;MyClass&gt;</code> called <code>myVector</code>.</p>
  
  <p>Now, I do this:</p>
  
  <pre><code>...
  myVector.add(new MyClass(1,1));
  for(MyClass m : myVector)
      System.out.println(m);
  System.out.println(myVector.size());
  
  myVector.remove(new MyClass(1,1));
  for(MyClass m : myVector)
      System.out.println(m);
  System.out.println(myVector.size());
  ...
  </code></pre>
  
  <p>The problem here is that the object isn't being removed, as I see when I print the Vector and its size. How could I fix that?</p>
  
  <p><strong>Edit:</strong> I can see that it isn't finding the object and I've tested with <code>contains()</code> to be sure. What I need is to compare it by value. If I could overload the <code>==</code> operator I could do it, but I have no idea how to fix this.</p>
  
  <p><strong>Edit 2:</strong> Okay, <code>equals()</code> will do what I want it to. But I'm not sure what to put in the hashCode method.</p>
  
  <p><strong>Edit 3:</strong> I can find it with contains(), but remove doesn't remove it. </p>
  
  <p>I can use this to remove it though:</p>
  
  <pre><code>int position = myVector.indexOf(new MyClass(1,1));
  myVector.remove(position);
  </code></pre>
  
  <p>Which is the same as remove(new MyClass(1,1), except the above code works and remove() doesn't. Any thoughts?</p>