-1

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.

enter image description here

PrintScreen in the link - http://picbg.net/img.php?file=b44ca20541c93f70.jpg

Tom Chantler
  • 14,753
  • 4
  • 48
  • 53

3 Answers3

0

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.

PermaFrost
  • 1,386
  • 12
  • 10
0

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]
Ruchira Gayan Ranaweera
  • 34,993
  • 17
  • 75
  • 115
0

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.

SparkOn
  • 8,806
  • 4
  • 29
  • 34