title: Remove In Range in an ArrayList
body: <p>I have the following requirements to write a java method.
  Write a method called <code>removeInRange</code> that accepts four parameters: a List of integers, an element value, a starting index, and an ending index. The method's behavior is to remove all occurrences of the given element that appear in the list between the starting index (inclusive) and the ending index (exclusive). Other values and occurrences of the given value that appear outside the given index range are not affected.</p>
  
  <p>For example, for the list (0, 0, 2, 0, 4, 0, 6, 0, 8, 0, 10, 0, 12, 0, 14, 0, 16), a call of removeInRange(list, 0, 5, 13) should produce the list (0, 0, 2, 0, 4, 6, 8, 10, 12, 0, 14, 0, 16). Notice that the zeros located at indices between 5 inclusive and 13 exclusive in the original list (before any modifications were made) have been removed.
  I have written the method as follows:</p>
  
  <pre><code>public static void removeInRange(List&lt;Integer&gt; list,int value,int beg,int end)
  {
      beg=new Integer(beg);
      //Integer b=beg;
      int count=0;
      list.subList(5, 13);
  /*  for( Integer b:list.subList(beg, end))
  
      {
          if(list.get(b)==value)
          list.remove(b);
      }
      */
      Iterator&lt;Integer&gt; iter = list.subList(beg, end).iterator();
      int i=iter.next();
      while(iter.hasNext())
      {
          if (iter.next().intValue()==value) 
          {
              iter.remove();
  
          }
  
      }
  
      System.out.println(list);
  }
  </code></pre>
  
  <p>However, this method gives me the error Exception in thread "main" <code>java.lang.UnsupportedOperationException</code>.I want any hints or suggestions how I can change my method to avoid this exception?</p>