scoreItemTableSourceVOSgetValuestream mapthisgetEachRowOfData collectCollectorstoList;scoreItemTableSourceVOS怎么判空 不使用if
可以使用Optional类的ofNullable方法来判空,然后使用map方法来对非空值进行操作,如果为空则返回一个空的Optional对象。代码如下:
scoreItemTableSourceVOS.stream() .map(Optional::ofNullable) .map(opt -> opt.map(this::getEachRowOfData)) .flatMap(Optional::stream) .collect(Collectors.toList());
原文地址: http://www.cveoy.top/t/topic/h9Dj 著作权归作者所有。请勿转载和采集!