I have two ArrayLists of objects: modelList
which contains Model
objects, and entityList
which contains Entity
objects. Both Model
and Entity
objects have a property called id
.
My goal is to loop through each Model
in modelList
and, if there is an Entity
in entityList
with the same id
value, call the method merge()
.
Currently, I am doing this:
for (Model model : modelList) {
for (Entity entity : entityList) {
if (model.getId().equals(entity.getId())) merge(entity, model);
}
}
This doesn't seem very efficient, especially with a large dataset. What would be a better way of achieving the desired result?
Thanks in advance!