I have a Class ArrayList so I have to delete duplicates Keywords when their Autor are same, but not when theses are different. The follow code remove duplicates OK only in the first Index (i=0), then it doesn't remove anything.
Thanks you!
Example:
Here I have an example :
1 A PPP
2 A EEE
3 B AAA
4 B LL
5 A CCC
2 A EEE
5 A CCC
In this cases I don't want to remove anyline because "A" has a different parent (2 and 5).
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 < size - 1; i++) {
for (int j = i + 1; j < size; j++) {
if(ls.get(j).getKeywords().equals(ls.get(i).getKeywords()) && 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