Few open points --
One, I would suggest using foreach
for DS like List
to iterate through.Take a look at How does the Java 'for each' loop work?
Two, use equals
to compare strings. Help - How do I compare strings in Java?
Third, use a counter variable, e.g. int counter = 0;
which can be used to count the number of duplicate occurrences as
if(actors.get(z).getName().equals(movieActors.get(n).getName())) { counter++; //currently just saving the count, you can save the name as well}
Updating from the comments discussion, to keep a count of actors that appeared in different movies :
You can maintain a Map<Actor,Count>
(not literally | more of Map<String, Integer>
) in general to store the count. and inside your if increment the count for each actor key.
Further to keep a unique list of actors, would suggest using Set
instead of ArrayList
. Please read How to use java.Set