title: I have to remove duplicates from list (special condition)
body: <p>I have a Class ArrayList so I have to <strong>delete duplicates Keywords</strong> when their Autor are same, but <strong>not when theses are different</strong>. The follow code remove duplicates OK only in the first Index (i=0), then it doesn't remove anything.</p>
  
  <p>Thanks you!</p>
  
  <p>Example:</p>
  
  <p>Here I have an example :</p>
  
  <p>1   A   PPP</p>
  
  <p>2   A   EEE</p>
  
  <p>3   B   AAA</p>
  
  <p>4   B   LL</p>
  
  <p>5   A   CCC</p>
  
  <p><strong>2 A   EEE</strong></p>
  
  <p><strong>5 A   CCC</strong></p>
  
  <p>In this cases I don't want to remove anyline because "A" has a different parent (2 and 5).</p>
  
  <pre><code>        int size = ls.size();
      int duplicates = 0;
  
      // not using a method in the check also speeds up the execution
      // also i must be less that size-1 so that j doesn't
      // throw IndexOutOfBoundsException
      for (int i = 0; i &lt; size - 1; i++) {
          for (int j = i + 1; j &lt; size; j++) {
  
                      if(ls.get(j).getKeywords().equals(ls.get(i).getKeywords()) &amp;&amp; ls.get(j).getAutor().equals(ls.get(i).getAutor()) ){
                          duplicates++;
                          ls.remove(j);}
  
  
              // decrease j because the array got re-indexed
              j--;
              // decrease the size of the array
              size--;
          } // for j
      } // fo
  </code></pre>