0

I have created an ArrayList from a comma separated string. Now I want to add an extra blank space to this list, but I am getting following error:

java.lang.UnsupportedOperationException
    at java.util.AbstractList.add(AbstractList.java:131)

My Code is

inputParamList=Arrays.asList(inputVariablesNames.split(","));
inputParamList.add("");
azurefrog
  • 10,785
  • 7
  • 42
  • 56

1 Answers1

1

The List returned by Arrays.asList is only a thin wrapper over an actual array, and you can't add elements to an array.

Returns a fixed-size list backed by the specified array. (Changes to the returned list "write through" to the array.)

Convert it to an ArrayList. Then you can add the extra element to the ArrayList.

inputParamList = new ArrayList<>(Arrays.asList(inputVariablesNames.split(",")));
rgettman
  • 176,041
  • 30
  • 275
  • 357