If it doesn't appear change the string to delete (remove) save and try again. In Eclipse Juno
I tried with new String(), instead of literals and happened the same.
PrintScreen in the link - http://picbg.net/img.php?file=b44ca20541c93f70.jpg
If it doesn't appear change the string to delete (remove) save and try again. In Eclipse Juno
I tried with new String(), instead of literals and happened the same.
PrintScreen in the link - http://picbg.net/img.php?file=b44ca20541c93f70.jpg
You are modifying the list while you are iterating over it - this does not work. You can try iterating it from back to front using a normal for
loop (with index, not a foreach
loop) and remove while iterating back to front.
Use Iterator
List<String> list=new ArrayList<>();
list.add("aaa");
list.add("bbb");
list.add("ccc");
list.add("ccc");
list.add("ddd");
Iterator<String> iterator=list.iterator();
while (iterator.hasNext()){
if("ddd".equals(iterator.next())){
iterator.remove();
}
}
System.out.println(list);
Output:
[aaa, bbb, ccc, ccc]
The problem occured here because you are iterating over the list and at the same time trying to manipulate it which ArrayList
does not support means
Detecting modification in the collection and parsing the collection is not done synchronously.
This behaviour is called Fail fast Iterators
.
Example for fail fast iterators are ArrayList
, HashSet
.