Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
99 views
in Technique[技术] by (71.8m points)

java - How to add elements in List when used Arrays.asList()

We cannot perform <Collection>.add or <Collection>.addAll operation on collections we have obtained from Arrays.asList .. only remove operation is permitted.

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?

question from:https://stackoverflow.com/questions/18389012/how-to-add-elements-in-list-when-used-arrays-aslist

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Create a new ArrayList using the constructor:

List<String> list = new ArrayList<String>(Arrays.asList("a", "b"));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...