Quotations
Alibaba java development standards when it comes to using tools Arrays.asList () method of the array into a collection, you can not use it to modify a set of related methods, its add / remove / clear method throws UnsupportedOperationException (), we look why this happens.
problem analysis
We have to be tested
Annotated can unlock three lines are comments, after running the statute does appear in the said exception. We look at Arrays.asList () to do what action.
It appears to be a normal way, but in fact you click through to the ArrayList found, in fact, is not what we usually use ArrayList ArrayList.
But an inner class Arrays inside. And this internal class does not add, clear, remove method, so exceptions thrown from the fact AbstractList.
Point into place you will find to throw an exception, clear bottom layer is also called to remove it will also throw an exception.
to sum up
1.Arrays.asList () not to use, but it is still the underlying array;
2. If a Arrays.asList (), it is best not to use its method of operation set;
3.List list = new ArrayList <> (Arrays.asList ( "a", "b", "c")) may be coated with a layer of such real ArrayList (array to a set There are many ways out, reference may be https: / /stackoverflow.com/questions/157944/create-arraylist-from-array).