List with multiple objects streaming: In this example tow values, titleValue and titleSortValue are given to list. While iterating through list using stream we can map it to particular string as needed and use it.
List<TitleDetail> titleDetailList = null;
List<String> titleValue = null;
List<String> titleSortValue = null;
if(checkIfNodeExist(doc, RELATED_ITEM_SERIES_XPATH)) {
try {
titleDetailList = processTitleInfoNodes(doc, RELATED_ITEM_SERIES_XPATH);
titleValue = titleDetailList.stream()
.map(TitleDetail::getTitleValue)
.collect(Collectors.toList());
bibData.setSeries(getPipeSeparatedStringFromList(titleValue));
bibDataES.setSeries(titleValue);
titleSortValue = titleDetailList.stream()
.map(TitleDetail::getTitleSortValue)
.collect(Collectors.toList());
bibDataES.setSeriesSort(titleSortValue);
} catch (XPathExpressionException e) {
LOG.error("Error processing related item series for bibid:" + bibData.getId());
}
}