0

I have got some issues in below codelines written in java 8

List<List<Integer>> list = Arrays.asList(Arrays.asList(1, 3), Arrays.asList(1, 2), Arrays.asList(1, 2));

Integer[][] arr1 = list.stream().map(l ->l.stream().mapToInt(Integer::intValue).toArray()).peek((x)->System.out.println(x[0]+","+x[1])).toArray(Integer[][]::new);

There is no compilation error at all; But I am getting exception as below. enter image description here

Although I am not getting any issue with primitive types but above stream fails with autobox the values. Please help.

Manojak
  • 149
  • 2
  • 3
  • 10
  • 2
    An `int[]` can not be stored in an `Integer[][]`. Either, you change `l.stream().mapToInt(Integer::intValue).toArray()` to `l.toArray(new Integer[0])` to get your `Integer[][]`, or you use `int[][] arr1 = list.stream().map(l -> l.stream().mapToInt(Integer::intValue).toArray()).peek(x -> System.out.println(x[0]+","+x[1])).toArray(int[][]::new);` instead. – Holger Jun 19 '23 at 12:28

0 Answers0