[英]add 2d arraylist to 3d arraylist
I have got 3d arraylist and to each dimension of it I want to add a temporary 2d arraylists. 我有3d arraylist,并且要向其每个维度添加一个临时2d arraylists。 For example
例如
List<List<Integer>> perm = new ArrayList<List<Integer>>();
List<List<List<Integer>>> list1 = new ArrayList<List<List<Integer>>>();
list1.get(0).add(perm);
list1.get(1).add(perm);
but this one does not work. 但这不起作用。 It tells me
告诉我
The method add(List<Integer>) in the type List<List<Integer>> is not applicable for the
arguments (List<List<Integer>>)
Look at the types more closely - you're trying to add a List<List<Integer>>
to the first list inside list1
(because you've called get(0)
.) 仔细观察类型-您正尝试将
List<List<Integer>>
到list1
内的第一个列表中(因为您已调用get(0)
。
This first list (inside the topmost ArrayList
) however is of type List<Integer>
, not List<List<Integer>>
- thus the types don't match, and you get a compile error. 但是,第一个列表(在最顶部的
ArrayList
)的类型为List<Integer>
,而不是List<List<Integer>>
-因此类型不匹配,并且会出现编译错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.