You can't add an item to a List<T>
returned by Arrays.asList(..)
:
Returns a fixed-size list backed by the specified array. (Changes to the returned list "write through" to the array.) This method acts as bridge between array-based and collection-based APIs, in combination with Collection.toArray().
You could use a separated List
that you build from the array manually or use directly just Arrays
:
String[] newStrings = Arrays.copyOf(myStrings, myStrings.length()+1);
newStrings[myStrings.length()] = addMe;