java.lang.IllegalStateException: Duplicate key ex-qixuie002

map中存在key值相同的数据

Map<String, String> collect = oList.stream().collect(
                Collectors.toMap(OcmCustomerIdDO::getOcmCustId, info -> info.getUmId() == null ? "" : info.getUmId()));
        System.out.println(collect);

  

 

根据业务逻辑选择,是前者覆盖后者重复,还是后者覆盖前者重复

Map<String, String> collect = oList.stream().collect(
                Collectors.toMap(OcmCustomerIdDO::getOcmCustId, OcmCustomerIdDO::getUmId, (key1, key2) -> key2));//后者覆盖前者

  

 

posted @ 2022-04-12 16:00  不忘初心2021  阅读(127)  评论(0编辑  收藏  举报