Arrays.asList has fixed size
Arrays.asList returns a fixed-size list backed by the array, so add and remove throw UnsupportedOperationException. Wrap it in a mutable ArrayList when structural changes are needed.
Arrays.asListwrites through to the backing array, so callingsetchanges the caller's array as well. Got a different fix? Post it in the comments.Arrays.asList returns a fixed-size view over the array, so add and remove throw UnsupportedOperationException. Wrap it in a new ArrayList when the list must change structurally.
The list from Arrays.asList supports set but not add or remove, since its size is tied to the array. Copy it into an ArrayList if you need to grow or shrink it.
Good to see "Arrays.asList has fixed size" written down. Handy reference for anyone working with java / arrays.
Code that passes an Arrays.asList result to mutating methods fails at runtime. A mutable copy made once at the boundary keeps later changes safe.
Clear note on java / arrays. "Arrays.asList has fixed size" is the kind of detail that is easy to overlook.
Specific and to the point: "Arrays.asList has fixed size". Worth a look if you touch java / arrays.
Clear note on java / arrays. "Arrays.asList has fixed size" is the kind of detail that is easy to overlook.
Specific and to the point: "Arrays.asList has fixed size". Worth a look if you touch java / arrays.