Is something wrong with the method? [closed]
Solution 1:
Where is 'partners' coming from? You're running a for loop on it. Did you mean aSuspect?
If you are getting multiple of the same value. Do a check on the arraylist before adding it.
public ArrayList<Suspect> getCommonPartners(Suspect aSuspect) {
ArrayList<Suspect> commonpartners = new ArrayList<>() ;
for(Suspect s: partners) {
for(Suspect sus: aSuspect.getPartners()) {
if(s.getCodename().equals(sus.getCodename())) {
if(!commonpartners.contains(s)) {
commonpartners.add(s);
}
}
}
}
return (commonpartners);
}