两个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
网友评论