Suppose I have this:
public class Unit {
...
List mobileSuits;
List pilots;
...
}
Came across this page trying to solve this issue, and turns out that there's a library out there that's already solved it using Java 8 streams (check out the Zip function).
You can convert a list to a stream just by calling list.stream()
https://github.com/poetix/protonpack
Stream streamA = Stream.of("A", "B", "C");
Stream streamB = Stream.of("Apple", "Banana", "Carrot", "Doughnut");
List zipped = StreamUtils.zip(streamA,
streamB,
(a, b) -> a + " is for " + b)
.collect(Collectors.toList());
assertThat(zipped,
contains("A is for Apple", "B is for Banana", "C is for Carrot"));