Java Stream API优化:将ScoreItemCellsVO列表转换为二维列表
可以将上述代码转换为使用Stream API的方式,如下所示:
List<ScoreItemCellsVO> scoreItemCellsVOS = scoreItemTableHeader.getScoreListName();
List<List<String>> head = scoreItemCellsVOS.stream()
.map(scoreItemCellsVO -> Collections.singletonList(scoreItemCellsVO.getLabel()))
.collect(Collectors.toList());
这里使用了Stream的map操作,将ScoreItemCellsVO对象映射为只包含一个元素的List,然后使用collect操作将所有List收集到一个List中。
原文地址: https://www.cveoy.top/t/topic/oZBc 著作权归作者所有。请勿转载和采集!