JAVA两个List<实体>实体类集合合并(实体类间 有一列值互相对应)

使用新集合将两个List<实体>合并放入

//json串转化为list<实体>
List<WayAssetsVo> wayAssetsVoList = JSONObject.parseArray(dataResult, WayAssetsVo.class);
//java8从已知集合获取集合
List<String> ageList = assetsData.stream().map(ReturnAssetsPO::getAssetsclass).distinct().collect(Collectors.toList());
//java8从已知集合获取集合
List<AssetAllocationVo> stationDictVOS = assetsData.stream().map(ReturnAssetsPO -> {
    AssetAllocationVo assetAllocationVo = new AssetAllocationVo();
    assetAllocationVo.setCategory(ReturnAssetsPO.getAssetsclass());
    return assetAllocationVo;
}).distinct().collect(Collectors.toList());

//合并集合assetConfigVo  wayAssetsVoList  创建新集合assetsMergedVos  把第一个合并集合assetConfigVo放入新集合assetsMergedVos
    List<AssetsMergedVo> assetsMergedVos = new ArrayList<>();
if (CollectionUtil.isNotEmpty(ConfigList)) {
    assetsMergedVos = ConfigList.stream().map(assetConfigVo -> {
        AssetsMergedVo assetsMergedVo = new AssetsMergedVo();
        assetsMergedVo.setA(assetConfigVo.getCategory());
        assetsMergedVo.setB(assetConfigVo.getInvqty());
        assetsMergedVo.setC(assetConfigVo.getConfigqty());
        return assetsMergedVo;
    }).collect(Collectors.toList());
}
//List循环遍历    把第二个List<实体>放入新的List<实体>
int count = 0;
for (int i = 0; i < assetsMergedVos.size(); i++) {
    for (int j = 0; j < wayAssetsVoList.size(); j++) {
        if (assetsMergedVos.get(i).getA().equals(wayAssetsVoList.get(j).getAssetsTypeCode())) {
                        assetsMergedVos.get(i).setD(wayAssetsVoList.get(j).getNum());
                        count = Integer.parseInt(assetsMergedVos.get(i).getC()) - Integer.parseInt(assetsMergedVos.get(i).getB()) - Integer.parseInt(wayAssetsVoList.get(j).getNum());
                        assetsMergedVos.get(i).setRes(String.valueOf(count));
                    }
                }
            }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值