I have a parent class Company which has a list of Employee objects. I need to create a stream of Parent class who has an Employee
Company
Employee
Parent
Use anyMatch for a predicate instead of flatMap as:
anyMatch
flatMap
List<Company> companiesWithEmployeesphone800 = companies.stream() .filter(loc -> loc.getEmployees().stream() .anyMatch(locnew -> locnew.getPhone().equalsIgnoreCase("800"))) .collect(Collectors.toList());