Lambda表达式根据主键ID将List<对象>转Map<Long, 对象>

本文通过具体示例展示了如何使用 Java Stream API 将列表转换为 Map,并解决元素冲突问题。利用 Stream API 的 toMap 方法结合自定义冲突解决策略,实现了高效的数据结构转换。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

List<YxhClientFormSubmitInfoDTO> yxhClientFormSubmitInfoDTOList = clientFormSubmitInfoResultList.getData();
Map<Long, YxhClientFormSubmitInfoDTO> submitInfoMap = yxhClientFormSubmitInfoDTOList.stream().collect(Collectors.toMap(YxhClientFormSubmitInfoDTO::getId, a -> a, (k1, k2) -> k1));

 

/** * 初始化多指标配置 * * @param req 请求信息 * @return 交易指标 */ private List<TransTargetMultIndex> convertMultIndex(TargetInitDto req) { if (Objects.equals(IndexTradeTypeEnum.MULTIPLE.getVal(), req.getIndexTradeType())) { List<TransTargetMultIndexDto> multIndexDtoList = req.getMultIndexList(); if (CollectionUtils.isEmpty(multIndexDtoList)) { log.error("[指标初始化]多指标交易请求信息不能为空,id=[{}]", req.getId()); throw new GpException("[指标初始化]多指标交易请求信息不能为空"); } List<TransTargetMultIndex> multIndexList = BeanUtil.copyToList(multIndexDtoList, TransTargetMultIndex.class); } return new ArrayList<>(); } /** * 多指标配置表 * * @TableName TRANS_TARGET_MULT_INDEX */ @TableName(value = "TRANS_TARGET_MULT_INDEX") @Data public class TransTargetMultIndex implements Serializable { /** * 主键ID */ @TableId private String id; /** * 标的id */ private String targetId; /** * 指标类型 */ private String indexType; /** * 指标报价排序 */ private Integer order; /** * 报价方式 1 循环竞价 2 一次性报价 */ private Integer priceMethod; /** * 起始价 */ private BigDecimal startPrice; /** * 竞价阶梯 */ private BigDecimal priceStep; /** * 1 向上竞价 2向下竞价 */ private Integer stepMethod; /** * 1 有最高报价 0 无最高报价 */ private Integer hasHighPrice; /** * 最高价格或最高比例或最低价 */ private BigDecimal highOrLowerPrice; /** * 价格单位 */ private String priceUnit; /** * 一起性报价最小价格 */ private BigDecimal oneTimeStartPrice; /** * 一次性报价最大价 */ private BigDecimal oneTimeEndPrice; /** * 1 中位数 2平均数 3次高价 */ private Integer oneTimeWinMethod; /** * 当前指标开始时间 */ private Date indexStartTime;} 对multIndexList 根据order字段从小到大排序,并设置indexNodeSort为1
04-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值