I need to iterate through an arrayList and add/remove elemets from it based on some conditions. The issue is that after adding/removing the arrayList's size changes and therefore I get a Null Pointer Exception error. Any help would be appreciated.
public class hello{
MyArrayList<Integer> list = new MyArrayList<>();
list.add(1);
list.add(2);
.......
for (int i = 0; i < list.size(); i++){
if(//some condition){
list.add(//something);
}
else if(//some condition){
list.remove(//something);
}
}
}