While studying the Collection
API, we find that some methods (add
, remove
,...) may throw a java.lang.UnsupportedOperationException>
Normally when you create a list like List
. The List sample
will be created as a Collections.unmodifiableCollection()
.
So the list sample does not support dynamic list operations. You can only assign another list to this list using assignment operator. Eg>
List ls=new ArrayList();
ls.add("one");
ls.add("Three");
ls.add("two");
ls.add("four");
sample = ls;
For dynamic list operations you should have a syntax like
List
. In this list you can perform sample.add(), sample.addAll()
etc...