title: List of Strings to hashmap using Streams
body: <p>I have a "," separated String array like this</p>
  
  <pre><code>a b c d,
  f b h j,
  l p o i,
  </code></pre>
  
  <p>I would like this to be converted to a Hashmap like
  <code>HashMap&lt;String, List&lt;String&gt;&gt;</code> such that second element in list (delimited by space becomes key and the 3rd element becomes value)
  So,
  This should become</p>
  
  <pre><code>b -&gt; c,h
  p -&gt; o
  </code></pre>
  
  <p>I want to use Streams API and I think this is the way to go:</p>
  
  <pre><code>List&lt;String&gt; entries = new ArrayList&lt;&gt;();
  HashMap&lt;String, List&lt;String&gt;&gt; map = new HashMap&lt;&gt;();
  
  HashMap&lt;String, List&lt;String&gt;&gt; newMap = entries.stream()
      .collect(line -&gt; {
          if (map.contains(line.split(" ")[1])) {
              // Get existing list and add the element
              map.get(line.split(" ")[1].add(line.split(" ")[1]));
          } else {
              // Create a new list and add
              List&lt;String&gt; values = new ArrayList&lt;&gt;();
              values.add(line.split(" ")[1]);
              map.put(line.split(" ")[0], values);
          }
      });
  </code></pre>
  
  <p>Is there any better way? How exactly should I return Hashmap from collect function?</p>