I'm receiving two object's List and I should compare all the objects...
For this I've been using the next loop:
for (int i=0;it2.hasNext();i++ ) {
objetoDb4o=it2.next();
tratdb4o=(Tratam)objetoDb4o;
for (int j=0;it.hasNext();j++ ) {
objetoJson = it.next();
tratJson = (Tratam)objetoJson;
}
}
it and it2 are iterators.. The values of size are correct (4 and 4)
But the loop doesn't work.. the first for iterates only one time, and the second for iterates three times.
I can not find the mistake! Can you help me please??
You need to reset the iterator it
before you enter the inner loop, otherwise you'll go through the second list only once during the first iteration of the outer loop; the remaining iterations will stop at it.hasNext()
, skipping the inner loop altogether.