Strange UnsupportedOperationException when calling list.remove(0)

后端 未结 5 1473
故里飘歌
故里飘歌 2021-01-23 17:04

I have this method which takes a varargs of Strings, creates a List out of it, and then tries to remove the first element of the list.

public void importFrom(Str         


        
5条回答
  •  心在旅途
    2021-01-23 17:43

    Arrays.asList() returns instance of Arrays.ArrayList that that is unmodifireable list because it is a simple wrapper over array. You cannot remove elements from array.

    This is written in javadoc of asList():

    Returns a fixed-size list backed by the specified array.

提交回复
热议问题