【发布时间】:2021-10-08 18:54:54
【问题描述】:
我在尝试比较两个大型集合时遇到性能问题,我正在寻求帮助以找到更好的方法。
课程:
public class TypeOne {
private int id;
}
和
public class TypeTwo {
private int id;
}
代码:
Collection<TypeOne> oneColl = someMethodToPopulateThat();
Collection<TypeTwo> twoColl = anotherMethodToPopulateThat();
// Iterating both collections to match the elements by id
for(TypeOne one : oneColl) {
for(TypeTwo two : twoColl) {
if (one.getId().equals(two.getId()))
System.out.println(one.getId());
}
}
我已经尝试使用 Stream API 的一些功能,但没有成功。 有没有人有任何想法来解决这个问题?请。
提前致谢。
【问题讨论】:
标签: java collections stream