Code :
ArrayList one = new ArrayList<>();
for(int i=1; i<=80; i++){
one.add(i);
if(i==40){
for(int j=21; j<=40; j++){
one.add(j);
}
}
}
ArrayList abc = new ArrayList<>(one);
System.out.println(abc);
for(int i=0; i<one.size(); i++){
if(i==20){
System.out.println(one.subList(i, i+20).size());
List<Integer> bb = one.subList(i, i+20);
System.out.println(bb);
ListIterator<Integer> lt= bb.listIterator();
while(lt.hasNext()){
int ind = one.indexOf(lt.next());
one.remove(ind);
}
}
}
Am I facing this issue due to fail fast iterators? What is the solution to remove the set of numbers (20 to 40) from the main list? (Only the first occurrence)?