title: Iterators in java - remove numbers in a range
body: <p>I'm trying to remove numbers from a LinkedList using an iterator. 
  I can't get it to remove numbers from only between to variables.</p>
  
  <p>My list contains these values: 1, 1, 2, 0, 4, 5, 6, 8, 8, 3, 11, 9, 12, 0, 14, 0, 16]</p>
  
  <p>The call of the method 
  <code>removeEvenInRange(list,5,13)</code>    should remove the even numbers between index 5 and 13, ending up with a list containing 
  <code>[1,1,2,0,4,5,3,11,9,0,14,0,16</code></p>
  
  <p>I don't know how to "tell" it to only iterate between the indexes 5 - 13. Any help on how to solve this would be much appreciated.</p>
  
  <p>This is what I have so far:</p>
  
  <pre><code>import java.util.Arrays;
  import java.util.Iterator;
  import java.util.List;
  import java.util.LinkedList;
  import java.util.ListIterator;
  
  public class Ex11_3_RemoveEvenInRange {
  
  public static void main(String[] args) {
  
      List&lt;Integer&gt; list = new LinkedList&lt;&gt;();
      list.addAll(Arrays.asList(1,1,2,0,4,5,6,8,8,3,11,9,12,0,14,0,16));
  
      removeEvenInRange(list, 5, 13);
  }
  
  private static void removeEvenInRange(List&lt;Integer&gt; list, int i, int j) {
  
  
              Iterator&lt;Integer&gt; itr = list.iterator();
  
              for (int k = i; k &lt; j; k++) {
  
                  int element = itr.next();
  
                  if (element % 2 == 0) {
                      itr.remove();
  
                  }
              }
  
  
                  System.out.println(list);
  
      }
  }
  </code></pre>