Answer the question
In order to leave comments, you need to log in
Why is an UnsupportedOperationException thrown?
List<Integer> list1 = Arrays.asList(10,20,60,30,22,70,89);
List<Integer> list2 = Arrays.asList(1,2,45,23,89,66,87,33,19,39);
//list1.forEach(System.out::println);
list1.addAll(list2);
Exception in thread "main" java.lang.UnsupportedOperationException // Throws addAll()
Answer the question
In order to leave comments, you need to log in
Array.asList()
is just a wrapper over an array with an interface List
. And arrays have a fixed size, so adding
and removing elements is not supported. If you want to fill with List
values from an array , then do this:List list = new ArrayList(Arrays.asList(1,2,3));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question