My question is that I am going to compare two arraylists in Java
e.g
String prop1 = "String"
String prop2 = "OtherString"
MyObject obj1 = new MyObject(prop1,prop2);
MyObject obj2 = new MyObject(prop1,prop2);
MyObject obj3= new MyObject(prop1,prop2);
ArrayList<MyObject> array1 = new Arraylist<>();
ArrayList<MyObject> array2 = new Arraylist<>();
//array 1 has 3 objects
array1.add(obj1);array1.add(obj2);array1.add(obj3);
//array 2 has 2 objects
array2.add(obj1);array2.add(obj2);
With a comparison method i know these arrays are different
(My method returns false if the arrays have the same elements even if they are not in the same order, and true if they have the same elements)
So, the method is going to return FALSE
My question is:
if(!methodToCompareArrays(array1,array2)){
//HOW TO GET THE DIFFERENT objects (IN THIS CASE, obj3 is the different object)
//this is the question :)
}else{
//If there is no difference, well, it doesn't matter too much
Notice that I'm going to have multiple objects into these arraylists, and also the method efficiency is important (not crucial, but important at least). I've seen the answers here But I'm not sure which one would be better or worst
Thanks in advance.