I am trying to see what possibility there is for something (don't tell me there isn't, this is my failed project) throughout an arrangement of points and their distances.
for (Point p1 : results) {
remove.clear();
for (Point p2 : results) {
if (Math.sqrt(
Math.pow(p1.getX() - p2.getX(), 2)
+ Math.pow(p1.getY() - p2.getY(), 2)
) % 1 > 0) {
results.remove(p2);
}
}
}
Basically, I am trying to check if two points have an integer distance, and, if not, remove it from the set, and do this for all points (that remain).
However, I am getting a ConcurrentModificationException
and I am not certain how to refactor it to accomplish the same task without just provoking the error in another way.
Are there any ways around this or is it just a limitation of Java?
EDIT: While the duplicate suggested link offers insight, the answers' focus on single loops has berth of excess that is not applicable. If this question is duplicate, it's on premise of that using an Iterator is just the answer.