Arrays.asList
returns a List
wrapper around an array. This wrapper has a fixed size and is directly backed by the array, and as such calls to set
will modify the array, and any other method that modifies the list will throw an UnsupportedOperationException
.
To fix this, you have to create a new modifiable list by copying the wrapper list's contents. This is easy to do by using the ArrayList
constructor that takes a Collection
:
Collection c = new ArrayList(Arrays.asList(la));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…