I have a class like this
public class Example {
private List ids;
public getIds() {
return this.ids;
}
}
Use flatMap
:
List<Integer> concat = examples.stream()
.flatMap(e -> e.getIds().stream())
.collect(Collectors.toList());
Another solution by using method reference expression instead of lambda expression:
List<Integer> concat = examples.stream()
.map(Example::getIds)
.flatMap(List::stream)
.collect(Collectors.toList());