使用JDK8的新特性:
OutpatientPayWayAccountVO vo = new OutpatientPayWayAccountVO(); vo.setIncomeAmount(new BigDecimal(100)); vo.setPayName("支付宝"); OutpatientPayWayAccountVO vo1 = new OutpatientPayWayAccountVO(); vo1.setIncomeAmount(new BigDecimal(0.2)); vo1.setPayName("微信"); OutpatientPayWayAccountVO vo2 = new OutpatientPayWayAccountVO(); vo2.setIncomeAmount(new BigDecimal(10)); vo2.setPayName("现金"); List<OutpatientPayWayAccountVO> list1 = new ArrayList<>(); list1.add(vo); list1.add(vo1); list1.add(vo2); OutpatientPayWayAccountVO vo_1 = new OutpatientPayWayAccountVO(); vo_1.setIncomeAmount(new BigDecimal(100)); vo_1.setPayName("支付宝"); OutpatientPayWayAccountVO vo_2 = new OutpatientPayWayAccountVO(); vo_2.setIncomeAmount(new BigDecimal(10)); vo_2.setPayName("微信"); OutpatientPayWayAccountVO vo_3 = new OutpatientPayWayAccountVO(); vo_3.setIncomeAmount(new BigDecimal(0.2)); vo_3.setPayName("现金"); List<OutpatientPayWayAccountVO> list_2 = new ArrayList<>(); list_2.add(vo_1); list_2.add(vo_2); list_2.add(vo_3); List<OutpatientPayWayAccountVO> list = list1.stream().map(m -> { list_2.stream().filter(m2-> m.getPayName().equals(m2.getPayName())).forEach(m2-> { m.setIncomeAmount(m.getIncomeAmount().add(m2.getIncomeAmount())); //m.put("incomeAmount",m2.getIncomeAmount().toString()); //m.put("age",m2.get("age")); }); return m; }).collect(Collectors.toList()); System.err.println("list:" + list);