关于JDK8对List的分组汇总

1. 跟据某个属性分组OfficeId:

 Map> collect = list.stream().collect(Collectors.groupingBy(IncomeSumPojo::getOfficeId));

 

2. 根据某个属性分组OfficeId,汇总某个属性Money:

Map collect = list.stream().collect(Collectors.groupingBy(IncomeSumPojo::getOfficeId,Collectors.summingDouble(IncomeSumPojo::getMoney)));

3. 根据某个属性添加条件过滤数据:

list = list.stream().filter(u -> !u.getAmount().equals("0.00")).collect(Collectors.toList());

 

4. 判断一组对象里面有没有属性值是某个值:

List

menuList = UserUtils.getMenuList();
boolean add = menuList.stream().anyMatch(m -> "plan:ctPlan:add".equals(m.getPermission()));

5. 取出一组对象的某个属性组成一个新集合:

List tableNames=list.stream().map(User::getMessage).collect(Collectors.toList());

 

6. list去重复:

list = list.stream().distinct().collect(Collectors.toList());

转载于:https://www.cnblogs.com/ZJOE80/p/10935611.html

你可能感兴趣的:(java)