title: Java Stream Collectors.toMap value is a Set
body: <p>I want to use a Java Stream to run over a List of POJOs, such as the list <code>List&lt;A&gt;</code> below, and transform it into a Map <code>Map&lt;String, Set&lt;String&gt;&gt;</code>.</p>
  
  <p>For example, class A is:</p>
  
  <pre><code>class A {
      public String name;
      public String property;
  }
  </code></pre>
  
  <p>I wrote the code below that collects the values into a map <code>Map&lt;String, String&gt;</code>:</p>
  
  <pre><code>final List&lt;A&gt; as = new ArrayList&lt;&gt;();
  // the list as is populated ...
  
  // works if there are no duplicates for name
  final Map&lt;String, String&gt; m = as.stream().collect(Collectors.toMap(x -&gt; x.name, x -&gt; x.property));
  </code></pre>
  
  <p>However, because there might be multiple POJOs with the same <code>name</code>, I want the value of the map be a <code>Set</code>. All <code>property</code> Strings for the same key <code>name</code> should go into the same set.</p>
  
  <p>How can this be done?</p>
  
  <pre><code>// how do i create a stream such that all properties of the same name get into a set under the key name
  final Map&lt;String, Set&lt;String&gt;&gt; m = ???
  </code></pre>