Is it safe to remove multiple items from an ArrayList while iterating through it with an iterator?
Iterator<String> iterator = nameList.iterator();
while(iterator.hasNext()){
String s = iterator.next();
List<String> list = work(s);
for (String s1 : list) {
nameList.remove(s1);
}
}
The work()
method gives back a list of names that should be removed from the nameList, during the runtime of while loop.