I'm getting this error when I try to check if any of the targets overlap each other:

iterTargets = targets.iterator();
while (iterTargets.hasNext()) {
    Target target = iterTargets.next();

    for (Target otherTarget:targets) {
        if (target.rectangle.overlaps(otherTarget.rectangle)) {
            // do something

So I can't do that? How am I supposed to check each member of an array to see if it overlaps any other member?


1 Answer 1


Try the following piece of code:

for(int i = 0; i < objects.size() - 1; ++i)
    for(int j = i + 1; j < objects.size(); ++j)
        //compare obj[i] and obj[j] - check collision here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .