title: Why does Collections.sort(List) work in Java 8 with CopyOnWriteArrayList but not in Java 7?
body: <p>I can sort a list of users without any problems using the following code and Java 8:</p>
  
  <pre><code>CopyOnWriteArrayList&lt;User&gt; allCurrentLoginnedUsersList = new CopyOnWriteArrayList&lt;&gt;(); 
  Collections.sort(allCurrentLoginnedUsersList);
  </code></pre>
  
  <p>Now, I changed to Java 7 and I saw no errors on eclipse. But now, when running under Java 7 I got this error:</p>
  
  <pre><code>java.lang.UnsupportedOperationException
      at java.util.concurrent.CopyOnWriteArrayList$COWIterator.set(CopyOnWriteArrayList.java:1049)
      at java.util.Collections.sort(Collections.java:221)
      at com.fluent.User.sortAllCurrentLoginnedUsers(User.java:446)
  </code></pre>
  
  <p>How to fix it?</p>