【发布时间】:2020-07-14 13:50:28
【问题描述】:
更新:
使用Integer[][]作为src数组类型可以使下面的代码工作。
我想将int[][] 转换为List<List<Integer>> 并尝试使用:
int[][] arr = new int[][]{{2}, {3, 4}, {6, 5, 7}, {4, 1, 8, 3}};
List<List<Integer>> ll = Arrays.stream(arr)
.map(Arrays::asList) // I expect this produces Stream<List<Integer>> but it was actually a Stream<List<int[]>>.
.collect(Collectors.toList());
编译器发出错误:
| Error:
| incompatible types: inference variable T has incompatible bounds
| equality constraints: java.util.List<java.lang.Integer>
| lower bounds: java.util.List<int[]>
| List<List<Integer>> ll = Arrays.stream(arr).map(Arrays::asList).collect(Collectors.toList());
| ^-----------------------------------------------------------------^
【问题讨论】:
-
@Naman 我看不出这个问题与任何链接问题的重复。
-
@hev1 你通过this answer了吗?