夜微凉、的博客

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

 

一个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()));

 

posted on 2022-04-15 16:14  夜、微凉  阅读(61)  评论(0编辑  收藏  举报