flatMap(Function<? super T,? extends Stream<? extends R>> mapper)
Returns a stream consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element.
중복된 스트림을 1차원으로 평면화 시키는 메서드입니다.
컬렉션 스트림의 모든 Elements를 mapping 함수에 적용하여 모든 컬렉션이 결합된 스트림으로 반환합니다.
List<String> students = Arrays.asList("bob", "sam");
List<String> results = students.stream()
.map(student -> student.split(""))
.flatMap(Arrays::stream)
.collect(Collectors.toList());
for(String result : results) {
System.out.println(result);
}
// 출력 예시: "b", "o", "b", "s", "a", "m"
private void writeInfraDataList(XMLStreamWriter out, List<AbstractReportDataVO> infraDataList) throws XMLStreamException {
List<ReportTableRowVO> reportTableRowList = infraDataList.stream()
.flatMap(reportData -> reportData.getReportTableRowList().stream())
.collect(Collectors.toList());
for(ReportTableRowVO reportTableRowVO : reportTableRowList) {
writeInfraData(out, reportTableRowVO);
}
}