ArrayStoreException at runtime in JAVA-8 Stream

29 views Asked by At

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.

0

There are 0 answers