[英]How to convert multiple attributes of object into List<String> using java 8
I am wondering if there is a way to combine multiple attributes from an object into a list of String. 我想知道是否有办法将一个对象的多个属性组合成一个String列表。 In My Case, I have an object with the name "debitCardVO" and I want it to convert from object to List 在我的案例中,我有一个名为“debitCardVO”的对象,我希望它从对象转换为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 flatMap
可以帮助你flatMap vs map
List<String> debitCardList = debitCardVOList.stream()
.flatMap(d -> Stream.of(d.getCardBranchCode(),d.getAccountNo()))
.collect(Collectors.toList());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.