Note: I am aware of the Iterator#remove()
method.
In the following code sample, I don\'t understand why the List.remove
in main
One way to handle it it to remove something from a copy of a Collection
(not Collection itself), if applicable. Clone
the original collection it to make a copy via a Constructor
.
This exception may be thrown by methods that have detected concurrent modification of an object when such modification is not permissible.
For your specific case, first off, i don't think final
is a way to go considering you intend to modify the list past declaration
private static final List integerList;
Also consider modifying a copy instead of the original list.
List copy = new ArrayList(integerList);
for(Integer integer : integerList) {
if(integer.equals(remove)) {
copy.remove(integer);
}
}