两个list高效合并

2021-03-08  本文已影响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;

    }
上一篇 下一篇

猜你喜欢

热点阅读