Quantcast
Viewing latest article 3
Browse Latest Browse All 7

Answer by Ahmed Raaj for How do I go through 2 list and check if the content of one element in the same as another element in a different list?

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;}

Viewing latest article 3
Browse Latest Browse All 7

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>