How can I make a copy of an iterator in Java? -
we have list of elements , have simplistic collision detection check every object against every other object.
the check commutative, avoid repeating twice, in c++:
for (list<object>::iterator it0 = list.begin(); it0 != list.end(); ++it0) { (list<object>::iterator it1 = it0; it1 != list.end(); ++it1) { test(*it0, *it1); } }
the key bit here copy
it1 = it0
how write in java?
you cannot copy java iterators, you'll have without them:
for(int i=0; i<list.size(); i++){ for(int j=i; j<list.size(); j++){ test(list.get(i), list.get(j)); } }
Comments
Post a Comment