美文网首页
两个list高效合并

两个list高效合并

作者: 少年眼蓝不及海 | 来源:发表于2021-03-08 17:26 被阅读0次

利用list.stream().cpllect(Collectors.toMap(a -> a.get_id(), a -> a))转map达到快速查找的目的。

public List<LiftEntity> fuseLiftState(List<LiftEntity> lifts, List<LiftState> liftStates){
        Map<String, LiftState> collect = liftStates.stream().collect(Collectors.toMap(a -> a.get_id(), a -> a));
        for (LiftEntity lift : lifts) {
            LiftState liftState = collect.get(lift.getLiftnumber());
            if (liftState == null) continue;
            lift.setLiftState(liftState);
        }
        return lifts;

    }

相关文章

网友评论

      本文标题:两个list高效合并

      本文链接:https://www.haomeiwen.com/subject/kzzpqltx.html