I have an ArrayList, which I want to divide into smaller Lists of n size, and perform an operation on each. My current method of doing this is
implemented with Array
// Testing data
List list = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
int n = 3;
// One line(statement) with java 8 stream and list.subList
List> partitions = IntStream.range(0, list.size())
.filter(i -> i % n == 0)
.mapToObj(i -> list.subList(i, Math.min(i + n, list.size() )))
.collect(Collectors.toList());