IntStream.iterate(0, i -> i + chunkSize)
.limit((long) Math.ceil((double) input.length / chunkSize))
.mapToObj(j -> Arrays.copyOfRange(input, j, j + chunkSize > input.length ? input.length : j + chunkSize))
.collect(Collectors.toList(ArrayList<int[]>::new));
}
I was trying to print array using Java 8 stream and it should return the type List<int[]> to the main function. example input are mentioned in the code.
The code is trying to create a
List<int[]>
, but the syntax used to create the list is incorrect. To fix this, you can replace the following line:with this line:
This will create a
List<int[]>
using the defaultList
implementation, which isArrayList
.Alternatively, you could specify the
ArrayList
implementation explicitly, like this:This will also create a
List<int[]>
using theArrayList
implementation.