Java: Sort an unmodifiable list

collections, java, list, sorting

Solution

Are you creating an empty list using `Collections.emptyList()`? If so, that is an unmodifiable list too and that may be the source of your problem.

Create a new list using the constructor for your List implementation, such as `new ArrayList()`. You can pass the original list into the constructor or else use the `addAll()` method.

Problem

How would one do this? I have tried creating a new, empty list, then copying unmodifiable list's elements to it, but I'm getting unsupported operation error. Any help is appreciated.

Original source