title: Remove duplicate in ArrayList of Custom objects
body: <p>i'm trying to remove duplicate objects from my array. </p>
  
  <p>I have my custom which is made of two double : x and y. </p>
  
  <p>What i want to do is to remove duplicate ( (x &amp;&amp; y) == (x1 &amp;&amp; y1)) and if x == x1 i want to keep the object which has the higher y. </p>
  
  <pre><code>ArrayList&lt;MyObject&gt; list = [x(0),y(0)], [x(0),y(0)], [x(0.5),y(0.5], [x(0.5),y(0.6)], [x(1),y(1)]; 
  ArrayList&lt;MyObject&gt; results = [x(0),y(0)], [x(0.5),y(0.6)], [x(1),y(1)]; 
  </code></pre>
  
  <p>I tried to implement the equals method but i do not how to use it : </p>
  
  <pre><code>public boolean equals(Object obj) {
      if (obj == null || !(obj instanceof MyObject)) {
          return false;
      }
      return (this.x == ((MyObject)obj).x);
  }
  </code></pre>
  
  <p>list is always ordered using Collections.sort by x. </p>
  
  <p>Thanks for all. </p>