1
I need to compare all the elements of a list 2 a 2 am doing as follows:
List: 1, 2, 3, 4.
Comparison: 1 and 2, 1 and 3, 1 and 4, 2 and 1, 2 and 3...
I’m using it as follows:
Iterator<Policie> p1Iterator = setOfPolicies.iterator();
Iterator<Policie> p2Iterator;
while(p1Iterator.hasNext()) {
p1 = p1Iterator.next();
count++;
p2Iterator = setOfPolicies.iterator();
while(p2Iterator.hasNext()) {
p2 = p2Iterator.next();
}
}
What I wanted to stop doing, is to compare for example: 1 and 2 & 2 and 1. Since it is the same for me. So since I compare the first with all the others, the second with all the others... The second time, for example, I would compare the second with everyone in front of it, the third with everyone in front of it, and so on. The problem is I can’t manipulate the positions with the iterator, which I could do?
It does not need to be with Iterator no, I did not know this method. I think so can solve, I will try here. Thanks.
– João Neto