It’s hard to help because you didn’t tell us how you like to compare (peer) collections. Some ideas, hoping one fits:
Compare both collections if they contain the same objects in the same order
Iterator targetIt = target.iterator();
for (Object obj:source)
if (!obj.equals(targetIt.next()))
// compare result -> false
,
for (Object obj:source)
if (target.contains(obj))
// compare result -> false
,
Iterator targetIt = target.iterator();
for (Object obj:source)
if (!obj.equals(targetIt.next())
, . , . , . equals() Car!
public List<Car> findUpdatedCars(Collection<Car> oldCars, Collection<Car> newCars)
List<Car> updatedCars = new ArrayList<Car>();
Iterator oldIt = oldCars.iterator();
for (Car newCar:newCars) {
if (!newCar.equals(oldIt.next()) {
updatedCars.add(newCar);
}
}
return updatedCars;
}