You can use the List.addAll() method.
(您可以使用List.addAll()方法。)
It accepts a Collection as an argument, and your set is a Collection. (它接受Collection作为参数,而您的集合就是Collection。)
List<String> mainList = new ArrayList<String>();
mainList.addAll(set);
EDIT: as respond to the edit of the question.
(编辑:作为对问题的编辑的回应。)
It is easy to see that if you want to have a Map
with List
s as values, in order to have k different values, you need to create k different lists.
(很容易看出,如果要使用一个List
为List
的Map
作为值,为了拥有k个不同的值,您需要创建k个不同的列表。)
Thus: You cannot avoid creating these lists at all, the lists will have to be created.
(因此:您完全无法避免创建这些列表,必须创建列表。)
Possible work around:
(可能的解决方法:)
Declare your Map
as a Map<String,Set>
or Map<String,Collection>
instead, and just insert your set.
(将Map
声明为Map<String,Set>
或Map<String,Collection>
,然后插入您的地图集。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…