Say I have this class
public class MovieCharacter {
private String name;
public String getName() { return name ; }
public String setName(String name) { this.name = name; }
}
I'm running a test and have a Set and I want to use a Lambda to comb through each object to see if it contains a desired String for the Name. If the name is found, a boolean is tripped to "true". After it's found, I don't want the boolean changed again.
Set<MovieCharacter> mySet // assume this Set has previously been created and
// contains 1,000's of MovieCharacter
boolean hasName = false;
mySet.forEach( i -> i.getName().equals("Darth Vader")) // add here?
assertTrue(hasName);
I know I'm close, but how would I finish the lambda line off so that if the set contains a MovieCharacter where .getName() returns "Darth Vader" the boolean would then get set to true? But if the the item of i under examination doesn't, it just keeps moving along?
Thanks!