Java8 Stream

1. string->int排序

resultList = totalList.stream().sorted(Comparator.comparing(s::getFinishRate, Comparator.comparingInt(Integer::parseInt)).reversed()).collect(toList());

2.List->Map

#值为对象中的字段
Map Map = totalList.stream().collect(Collectors.toMap(s::getOrgId, s::getGridCount, (v1, v2) -> v2));
#值为对象本身
Map map = wgList.stream().collect(Collectors.toMap(WgrbStatistic::getOrgId, item->item));

3.List-> Sum

String count = String.valueOf(resultList.stream().map(s::getCountFinish).mapToInt(Integer::parseInt).sum());

你可能感兴趣的:(Java8 Stream)