The following example may be trivial, but I have created it to show what I need to achieve using different data (not integers). This code is runnable etc.
List<List<Integer>> master = new ArrayList<>();
for (int i = 0; i < 10; i++) {
List<Integer> inner = new ArrayList<Integer>();
master.add(inner);
for (int j = 0; j < 10; j++) {
inner.add(i * 10 + j);
}
}
System.out.println(master);
//lets make single collections from that but add 1000 to every element - this represents some intermediate operations to generate part of final result
List<Integer> finalAccumulated = new ArrayList<Integer>(); // this will represent our accumulated, final result
for (List<Integer> topLvl : master) {
ArrayList<Integer> intermedialeAccumulated = new ArrayList<>(); //this step is important as it represents returning a collection of results for stream#map not single result
for (Integer nested : topLvl) { // this represents stream#map (or maybe collector?)
intermedialeAccumulated.add(nested + 1000);
}
finalAccumulated.addAll(intermedialeAccumulated); // this represent accumulation of collection of results, not just single result like stream#map do
}
System.out.println(finalAccumulated);
How to get the same result as in finalAccumulated
using single Stream
. By single I mean that in call chain there can be only single terminate action so the resulting form would be
finalAccumulated=master.stream()...intermediateCalls()...terminateCollectingCall();
Online ide with running code here