I'm trying to create a List<Object> aggregated based on List<Object> pool1 and List<Object> pool2. The main concern here is obviously performance since we have to compare every object in pool1 to every object in pool2. Is List necessary the best option?
Bad code version of the above:
List<Object> pool1 = new ArrayList<>();
List<Object> pool2 = new ArrayList<>();
List<Object> matchingObjects = new ArrayList<Object>();
for (Object p1 : pool1) {
    for (Object p2 : pool2) {
        if (p1.equals(p2)) {
            matchingObjects.add(p1);
        }
    }
}
 
    