It sounds like you have a List<Manager>
and each one has a List<Company>
, and you want to get a new list of companies that fall under some subset of those managers. If that is what you are trying to do, and you want to do it with streams, then you need something like this:
List<Company> companies = managers.stream().
.filter(/* limit to managers you want */)
.map(Manager::getCompanies) // get each manager's list
.flatMap(Collection::stream) // combine the lists
.collect(Collectors.tolist());
If you have to worry about nulls you can add .filter(Objects::nonNull)
after the .map()
line.