You need to use flatMap
:
lines.map(x -> (A)gson.fromJson(x, type)).flatMap(a -> Arrays.stream(a.getB())
Now this is a Stream<B>
; you can match this with their ids now
.map(B::getId)
and make a list of it.
.collect(Collectors.toList());
source
share