我想知道是否有一种方法可以将一个对象的多个属性组合成一个字符串列表。在我的案例中,我有一个名为“debitCardVO”的对象,我希望它从对象转换为列表
这是我的代码片段:
for (DebitCardVO debitCardVO : debitCardVOList) {
List<String> debitCardList = debitCardVOList.stream()
.map(DebitCardVO::getCardBranchCode,DebitCardVO::getAccountNo)
.collect(Collectors.toList());
}
最佳答案
flatMap
可以帮到你flatMap vs map
List<String> debitCardList = debitCardVOList.stream()
.flatMap(d -> Stream.of(d.getCardBranchCode(),d.getAccountNo()))
.collect(Collectors.toList());
关于java - 如何使用 java 8 将对象的多个属性转换为 List<String>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54572770/