一个List对象转换为另一个List对象
List<ProjectResponse> projectResponseList = morphBriefInfos.stream().map((entity) -> { ProjectResponse vo = new ProjectResponse(); vo.setProjectId(entity.getId()); vo.setProjectName(entity.getTitle()); return vo; }).collect(Collectors.toList());
求和
var distributorContractDetailAll = new ArrayList<MdDistributorContractDetailExtDTO>(); var distributorContractDetailSum = distributorContractDetailAll.stream() .filter(a -> a.getCcDetailId() == detailItem.getId()) .map(t -> t.getTaxCost().add(t.getFcTaxCost()).add(t.getDistributorTaxCost())) .reduce(BigDecimal.ZERO, BigDecimal::add);
转map map<string,List> 格式
List<MdCustomerContractDetailEntity> customerContractDetail=new List<MdCustomerContractDetailEntity>(); var distributorContractDetailMap = customerContractDetail.stream().collect(Collectors.groupingBy(a -> a.getDcId(), Collectors.toList()));