title: Using groupingBy to create a Map with immutable list as the key
body: <p>Say, I've a class called Project,</p>
  
  <pre><code>class Project {
      private String projectId;
      private String projectName;
  }
  </code></pre>
  
  <p>and a class called Employee, which has a list of projects</p>
  
  <pre><code>class Employee {
      private String name;
      private List&lt;Project&gt; projects
  }
  </code></pre>
  
  <p>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</p>
  
  <pre><code>Map&lt;List&lt;Project&gt;, Set&lt;Employee&gt;&gt; x =
          employees
          .stream
          .collect(Collectors.groupingBy(Employee::getProjects, Collectors.toSet()));
  </code></pre>
  
  <p>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?</p>
  
  <p>Thanks. </p>