I donβt understand why you use groupingBywhen you are not grouping at all. It seems you need to create Mapwhere the key is in Employeeand the value is Employeecars:
Map<Employee, List<Car> map =
emps.stream().collect(Collectors.toMap(Function.identity(),Employee::getCars);
, Employee, toMap :
Map<Employee, List<Car> map =
emps.stream()
.collect(Collectors.toMap(Function.identity(),
Employee::getCars,
(v1,v2)-> {v1.addAll(v2); return v1;},
HashMap::new);
, List, Employee::getCars, List .