We cannot perform <Collection>.add or <Collection>.addAll operation on collections we have obtained from Arrays.asList .. only remove operation is permitted.
<Collection>.add
<Collection>.addAll
Arrays.asList
So What if I come across a scenario where I require to add new Element in List without deleting previous elements in List?. How can I achieve this?
List
Create a new ArrayList using the constructor:
ArrayList
List<String> list = new ArrayList<String>(Arrays.asList("a", "b"));
2.1m questions
2.1m answers
60 comments
57.0k users