<qhelp> <overview>

The `remove` method of the `Iterator` interface is an optional operation. It is not supported by iterators on unmodifiable collections, or iterators on lists constructed by the `Arrays.asList` method. Invoking `remove` on such an iterator will lead to an `UnsupportedOperationException`.

</overview> <recommendation>

If a collection is meant to be modified after construction, use a modifiable collection type such as `ArrayList` or `HashSet`.

</recommendation> <example>

In the following example, the constructor `A(Integer...)` initializes the field `A.l` to `Arrays.asList(is)`. While the type of lists returned by `Arrays.asList` supports element updates through the `set` method, it does not support element removal. Hence the call to `iter.remove` on line 20 must fail at runtime.

To avoid this failure, copy the list returned by `Arrays.asList` into a newly created `ArrayList` like this:

</example> <references>

- Mark Needham: Java: Fooled by java.util.Arrays.asList.
</references> </qhelp>