Say, I've a class called Project,
class Project {
private String projectId;
private String projectName;
}
and a class called Employee, which has a list of projects
class Employee {
private String name;
private List<Project> projects
}
I also have a list of Employee objects. Now, I need to create a Map with the list of projects as the key and a set of employee objects as the value from this list. I can get it working by
Map<List<Project>, Set<Employee>> x =
employees
.stream
.collect(Collectors.groupingBy(Employee::getProjects, Collectors.toSet()));
However, since I'm using List as the key, I want to be extra careful and make sure that the list is immutable. Is there a way to achieve this?
Thanks.
, ...>`.
– assylias Oct 13 '17 at 11:17