title: Why collection methods like add(Object o),remove (Object o) don't work inside an iteration to remove or update?
body: <p>I have to check whether a number is even or not in an <code>ArrayList</code> collection from 0-10 numbers.  Using an <code>Iterator</code>, I have to print all even numbers inside that <code>ArrayList</code> and remove odd numbers from the <code>ArrayList</code>.</p>
  
  <pre><code>package hemantdhanuka;
  
  import java.util.*;
  
  public class Iteratorr {
  
      public static void main( String [] args) {
          ArrayList v = new ArrayList ();
          for( int i = 0; i &lt;= 10; i++ ) {
              v.add ( i );
          }
          System.err.println ( v );
          Iterator i = v.iterator ();
          /*while ( i.hasNext () ) {
              Integer a = ( Integer ) i.next ();
              if ( i % 2 == 0 ) {
                  System.out.println ( i );
              } else {
                  i.remove ();
              }
          }       
          System.out.println ( v );
          */
          while( i.hasNext () ) {
              Integer a = ( Integer) i.next ();
              if ( a % 2 == 0 ) {
                  System.out.println ( a );
              } else {
                  v.remove ( a );
              }
          }
          System.out.println ( v );
      }
  }
  </code></pre>
  
  <p>I know commented code will work properly but <strong>what about non commented code</strong>?  If I try to use <code>ArrayList#remove(Obj o)</code>  to remove odd number from <code>ArrayList</code> then it is not working. WHY</p>