java优化代码返回Liststring ListListString collect = manageToolConfigListstream filterf - StringUtilsequalsfgetType StringvalueOfActivityToolTypeEnumSCORE_STATISTICSgetValue sorted
如果你想要优化这段代码,可以考虑使用方法引用来代替Lambda表达式,并且使用ArrayList来代替默认的Collectors.toList()方法返回的List实现。下面是优化后的代码:
List<String> collect = manageToolConfigList.stream()
.filter(f -> StringUtils.equals(f.getType(), String.valueOf(ActivityToolTypeEnum.SCORE_STATISTICS.getValue())))
.sorted()
.map(item -> getScoreCensusToolResult(item.getCode(), enablePriority))
.collect(Collectors.toCollection(ArrayList::new));
这样,优化后的代码将返回一个List<String>对象。
原文地址: https://www.cveoy.top/t/topic/hHIw 著作权归作者所有。请勿转载和采集!