I am wondering if there is a way to combine multiple attributes from an object into a list of String. In My Case, I have an object with the name "debitCardVO" and I want it to convert from object to List
Here is my code Snippet:
for (DebitCardVO debitCardVO : debitCardVOList) {
List<String> debitCardList = debitCardVOList.stream()
.map(DebitCardVO::getCardBranchCode,DebitCardVO::getAccountNo)
.collect(Collectors.toList());
}
flatMap
can help you flatMap vs map
List<String> debitCardList = debitCardVOList.stream()
.flatMap(d -> Stream.of(d.getCardBranchCode(),d.getAccountNo()))
.collect(Collectors.toList());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.