尝试从列表中删除项目时出错:“UnsupportedOperationException”

时间:2017-12-13 17:33:40

标签: java eclipse list

如何从Java中的List中删除元素?这就是我试过的:

import java.util.Arrays;
import java.util.List;

public class Test{

    public static void main(String[] args) {

        String words = "monday|tuesday|wednesday|thursday|friday|saturday|sunday";

        List<String> list = Arrays.asList(words.split("\\|"));

        System.out.println(list.toString());

        list.remove(1);

        System.out.println(list.toString());
    }
}

我想要打印[monday, tuesday, wednesday, thursday, friday, saturday, sunday]
之后[monday, wednesday, thursday, friday, saturday, sunday]

但那确实不起作用...... 它会打印第一件事,但不是在那之后打印新的List,它在Eclipse中给了我这个错误:

Exception in thread "main" java.lang.UnsupportedOperationException
    at java.util.AbstractList.remove(Unknown Source)
    at Test.main(Test.java:14)

0 个答案:

没有答案