使用时如何在List中添加元素Arrays.asList() [英] How to add elements in List when used Arrays.asList()
本文介绍了使用时如何在List中添加元素Arrays.asList()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们无法对我们拥有的藏品执行< Collection> .add
或< Collection> .addAll
从 Arrays.asList
获得..只允许删除操作。
We cannot perform <Collection>.add
or <Collection>.addAll
operation on collections we have obtained from Arrays.asList
.. only remove operation is permitted.
那么如果我遇到需要在 List
中添加新元素而不删除以前元素的情况怎么办? 列表
?我怎样才能做到这一点?
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?
推荐答案
使用以下方法创建一个新的 ArrayList
构造函数:
Create a new ArrayList
using the constructor:
List<String> list = new ArrayList<String>(Arrays.asList("a", "b"));
这篇关于使用时如何在List中添加元素Arrays.asList()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文