I have an array of size 1000. I want to use the stream operations to performe like this :-
List list= new ArrayList();
//list is initialize to 1000 elements
List subList = list.subList(0, 100);
// perform some operaions over the subarray
List subList1 = list.subList(101, 200);
// perform some operaions over the subarray
.... so on
}
I want code using stream API. Thanks in advance
What about :
List<List<Integer>> result = IntStream.range(0, list.size() / 100)
.mapToObj(index -> list.subList(index * 100, index * 100 + 100))
.collect(Collectors.toList());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With