Stream流中将集合转成map

    public Map<Long, String> findBusinessUnitMapBySoids(List<Long> businessUnitSoids) {
        ListResult<List<BusinessUnitVo>> listBySoids = iBusinessUnitApi.findListBySoids(businessUnitSoids);
        Map<Long, String> res = new ConcurrentHashMap<>();
        if (ObjectUtils.isEmpty(listBySoids) || ObjectUtils.isEmpty(listBySoids.getData())) {
            return res;
        } else {
            List<BusinessUnitVo> BusinessUnitVos = listBySoids.getData();
            res = BusinessUnitVos.stream().filter(ObjectUtil::isNotEmpty)
                    .filter(a -> ObjectUtil.isNotEmpty(a.getBusinessUnitSoid()))
                    .filter(a -> ObjectUtil.isNotEmpty(a.getBusinessUnitName()))
                    .collect(Collectors.toMap(a -> a.getBusinessUnitSoid(), BusinessUnitVo::getBusinessUnitName, (key1, key2) -> key2));
        }
        return res;
    }

Stream流中将集合转成map_第1张图片

    public Map<String, OppBasicData> OppBasicDataMap(Boolean updateFlag) {
        LambdaQueryWrapper<OppBasicData> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(OppBasicData::getUpdateFlag,updateFlag);
        Map<String, OppBasicData> stringOppBasicDataMap = Optional.ofNullable(list(queryWrapper))
                .map(list -> list.stream()
                        .filter(oppBasicData -> ObjectUtils.isNotEmpty(oppBasicData.getOppCode()))
                        .collect(Collectors.toMap(OppBasicData::getOppCode, Function.identity(), (key1, key2) -> key2)))
                .orElse(new HashMap<>());
        return stringOppBasicDataMap;
    }

你可能感兴趣的:(JAVA,stream,filter,lambda)