Remove every thing from else condition and replace with following code. Though its not an optimal solution but might serve your purpose.
else { List<Actor> movieActors = (List<Actor>) x.getListOfActors(); for (int z = 0; z < x.getListOfActors().size(); z++) { Actor actor = movieActors.get(z); if (actors.contains(actor)) { actors.get(actors.indexOf(actor)).addCount(); }else{ actors.add(actor); } } }
And you have to Override equals method in Actor class
@Overridepublic boolean equals(Object obj) { if(obj instanceof Actor){ Actor a = (Actor)obj; if(this.name.equals(a.name)){ return true; } } return false;}