title: Why does List.remove(int) throw java.lang.UnsupportedOperationException?
body: <p>I am trying to remove elements from a <code>List</code> and getting <code>java.lang.UnsupportedOperationException</code>.</p>
  
  <pre><code>    public &lt;T extends Object&gt; void findDuplicates(
          String title, Multimap&lt;T, ChunkId&gt; map) {
          for (T key : map.keySet()) {
              Collection&lt;ChunkId&gt; ids = map.get(key);
              List&lt;ChunkId&gt; idList = (Arrays.asList(ids.toArray(new ChunkId[0])));
              removeUsedIds(idList);
              Collections.sort(idList);
  //...
          }
      }
  
      private void removeUsedIds(List&lt;ChunkId&gt; idList) {
          // decrement counter to avoid indexing changed parts of list
          for (int i = idList.size() - 1; i &gt;= 0; i--) {
              if (usedIdSet.contains(idList.get(i))) {
                  idList.remove(i);   // **** Exception thrown here
              }
          }
      }
  </code></pre>
  
  <p>and I get</p>
  
  <pre><code>Exception in thread "main" java.lang.UnsupportedOperationException
      at java.util.AbstractList.remove(Unknown Source)
      at org.xmlcml.svg2xml.analyzer.PDFIndex.removeUsedIds(PDFIndex.java:104)
      at org.xmlcml.svg2xml.analyzer.PDFIndex.findDuplicates(PDFIndex.java:87)
      at org.xmlcml.svg2xml.analyzer.PDFIndex.findDuplicatesInIndexes(PDFIndex.java:129)
      at org.xmlcml.svg2xml.analyzer.PDFAnalyzer.analyzePDF(PDFAnalyzer.java:188)
      at org.xmlcml.svg2xml.analyzer.PDFAnalyzer.analyzePDFFile(PDFAnalyzer.java:115)
      at org.xmlcml.svg2xml.analyzer.PDFAnalyzer.main(PDFAnalyzer.java:398)
  </code></pre>
  
  <p>NOTE: This is flagged as a duplicate of <a href="https://stackoverflow.com/questions/7885573/remove-on-list-created-by-arrays-aslist-throws-unsupportedexception">remove() on List created by Arrays.asList() throws UnsupportedOperationException</a> but it's significantly different. That poster <em>knew</em> what the problem was and wanted an explanation; I <em>did not know what the problem was</em> and couldn't find it on SO by posting the current question. Java 6 docs (<a href="http://docs.oracle.com/javase/6/docs/api/java/util/ArrayList.html" rel="noreferrer">http://docs.oracle.com/javase/6/docs/api/java/util/ArrayList.html</a>) gives no hint of the problem (its signature throws <code>IndexOutOfBoundsException</code>). The previous question also used <code>removeAll()</code> while this question referred to <code>remove(int)</code> so lexical searching is less precise.</p>
  
  <p>I therefore asked on SO and got rapid and useful answers. Because I phrased the title exactly (unlike the previous question) it should be easy for others to find this answer. In less than a day it already has nearly as many votes as the previous question in a year (and 100+ views), suggesting that it will be significantly more useful.  Since this question is now linked to the previous one I think it adds to the general usefulness without polluting SO. (The current answers are short and don't unnecessarily repeat information.)</p>
  
  <p>I have edited the question to remove extraneous code. If this question had been available when I encountered the problem it would have saved me an hour!</p>