I would like to compare the Objects of two Arrays and obtain a new Array with the Objects that did not match. This is: Array1 Array2 both contain Object User with methods getId and getUsername
for (int fw = 0; fw < tempOldArray.size(); fw++) {
for (int fi = 0; fi < tempArray.size(); fi++) {
if (tempOldArray.get(fw).getId() == tempArray.get(fi).getId()) {
match++;
break;
}
if(fi == (tempArray.size()-1)) {
nomatchfound++;
break;
}
}
}
Array1: {[1231, Peter], [2562, Jackson], [38987, Robert], [4765, William]}
Array2: {[2562, Jackson], [7584, Alfred], [38987, Robert], [8123, Mozart]}
Array3 should output {[1231, Peter], [4765, William]}
and Array4 should output {[7584, Alfred], [8123, Mozart]}
Also questioned about how to retrieve a result from list
{"peter", "trump", "donald", "jerry"}
{"peter", "donald", "lucas", "jerry"}
and output non matching ones