I am looking for a way to filter only the Worker objects with a specific first name and empty lastName from the given HashSet
. For example I want the code to return the record with firstName == scott and lastName == ""
.
public static void main(String[] args) {
Worker w1 = new Worker("scott","tiger");
Worker w2 = new Worker("panthera","tigris");
Worker w3 = new Worker("scott","");
Worker w4 = new Worker("alpha","romeo");
Worker w5 = new Worker("apple","orange");
Set<Worker> wset = new HashSet<>();
wset.add(w1);
wset.add(w2);
wset.add(w3);
wset.add(w4);
wset.add(w5);
System.out.println(wset.stream().filter(worker -> worker.firstName == "scott" && --something on these lines??--)); // ???
}