How can I remove an Element from a List
in Java? This is, what I tried:
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());
}
}
And I want it to print [monday, tuesday, wednesday, thursday, friday, saturday, sunday]
and [monday, wednesday, thursday, friday, saturday, sunday]
after that.
But that doesn't really work...
It prints the first thing but instead of printing the new List
after that, it gives me this error in Eclipse:
Exception in thread "main" java.lang.UnsupportedOperationException
at java.util.AbstractList.remove(Unknown Source)
at Test.main(Test.java:14)