Java 使用stream()两个集合根据元素中的某个字段取交集
时间:2020-08-15 22:55:37
收藏:0
阅读:2338
list1<Bean1>和list2<Bean2> 根据元素的playerId属性 取交集
Bean1和Bean2 都含有playerId属性
List<Bean1> intersectList = list1.stream()
.filter(pe -> find1(pe.getPlayerId(), list2) > -1).collect(Collectors.toList());
辅助方法find1
public int find1(long playerId,List<PlayerExtra> list) { int res = -1; for (int i = 0; i < list.size(); i++) { if (list.get(i).getPlayerId() == playerId) { res = i; break; } } return res; }
原文:https://www.cnblogs.com/erlongxizhu-03/p/13510067.html
评论(0)