I have a performance issue trying to compare two big Collections and I'm looking for some help to find a better way to do that.
The classes:
public class TypeOne {
private int id;
}
and
public class TypeTwo {
private int id;
}
The code:
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());
}
}
I already tried to use some functions of Stream API but I didn't get success. Does anyone have any idea to solve this issue? Please.
Thanks in advance.