Java: Why does calling `remove()` on a List throw UnsupportedOperation exception?
<p>For some reason, I'm getting an <code>UnsupportedOpeationException</code> with the following code. Examining it in the debugger, it looks like the object I'm calling <code>remove()</code> on is a list.</p>

<pre><code>// to optimize, remove totalSize. After taking an item from lowest, if lowest is empty, remove it from `lists`
// lists are sorted to begin with
public static &lt;T extends Comparable&lt;? super T&gt;&gt; List&lt;T&gt; merge(Set&lt;List&lt;T&gt;&gt; lists) {
 List&lt;T&gt; result = new ArrayList&lt;T&gt;();
 HashMap&lt;List&lt;T&gt;, Integer&gt; location = new HashMap&lt;List&lt;T&gt;, Integer&gt;();

 int totalSize = 0; // every element in the set
 for (List&lt;T&gt; l : lists) {
  location.put(l, 0);
  totalSize += l.size();
 }

 boolean first;
 List&lt;T&gt; lowest = lists.iterator().next(); // the list with the lowest item to add
 int index;

 while (result.size() &lt; totalSize) { // while we still have something to add
  first = true;

  for (List&lt;T&gt; l : lists) {
   if (! l.isEmpty()) {
    if (first) {
     lowest = l;
    }
    else if (l.get(location.get(l)).compareTo(lowest.get(location.get(lowest))) &lt;= 0) {
     lowest = l;
    }
   }
  }
  index = location.get(lowest);
  result.add(lowest.get(index));
  lowest.remove(index); //problem here
 }
 return result;
}
</code></pre>

<p>The exception:</p>

<pre><code>Exception in thread "main" java.lang.UnsupportedOperationException
    at java.util.AbstractList.remove(Unknown Source)
    at interview.questions.MergeLists.merge(MergeLists.java:72)
    at interview.questions.MergeLists.main(MergeLists.java:32)
</code></pre>

<p>Why is this happening?</p>
