Hi
I have written this part of code .before the for loop I have this arraylist :
[X :49.0 Y: 113.0 , angle :0.0, X :141.0 Y: 106.0 , angle :0.0, X :110.0 Y: 185.0 , angle: 1.0768211289482128, X :99.0 Y: 139.0 , angle: 1.9961041242180873, X :103.0 Y: 126.0 , angle : 2.4208694638343324]
which show "x" and "y" and "angle" of some points.
but in the for loop I want to remove those elements that are more than
X :110.0 Y: 185.0 , angle: 1.0768211289482128
BUT it print this array for me :
[X :49.0 Y: 113.0angle0.0, X :141.0 Y: 106.0 , angle:0.0, X :110.0 Y: 185.0 , angle: 1.0768211289482128, X :103.0 Y: 126.0 , angle: 2.4208694638343324]
which is incorrect
int size = list .size();
for (int i=0;i<size;i++) {
if (list.get(i).getAngle() > pivot.getAngle() ) {
list.remove(i);
size--;
}
}
please help me
thanks
Whenever you remove an element it shifts the indices of the following elements down by 1. The simplest fix is to go in reverse: