Removing numbers from a character list using java
<p>I wanted to display the numbers occuring in a character list and then remove that number. Here is my code:</p>

<p>package mytrials;</p>

<pre><code>import java.util.ArrayList;
import java.util.ListIterator;

public class MyTrials {
    public static void main(String[] args) {
    ArrayList&lt;Character&gt; list = new ArrayList&lt;Character&gt;();
    list.add('a');
    list.add('1');
    list.add('5');
    System.out.println(list.size());
    for( ListIterator i = list.listIterator(list.size());  i.hasPrevious();){
        Character c = (Character) i.previous();
        if( Character.isDigit(c)){
            System.out.println(c + " is a digit");
            list.remove(c);
        }
    }
    System.out.println(list.size());
}
}
</code></pre>

<p>Here is the error message:</p>

<pre><code>3
5 is a digit
Exception in thread "main" java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)
at java.util.AbstractList$ListItr.previous(AbstractList.java:386)
at mytrials.MyTrials.main(MyTrials.java:27)
Java Result: 1
</code></pre>

<p>What is the cause of this error and how can it be rectified.</p>
