Why do I get an UnsupportedOperationException when trying to remove an element from a List?

后端 未结 17 2248
后悔当初
后悔当初 2020-11-22 07:43

I have this code:

public static String SelectRandomFromTemplate(String template,int count) {
   String[] split = template.split(\"|\");
   List         


        
17条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-22 07:57

    Probably because you're working with unmodifiable wrapper.

    Change this line:

    List list = Arrays.asList(split);
    

    to this line:

    List list = new LinkedList<>(Arrays.asList(split));
    

提交回复
热议问题