title: Java 8 map list to map of lists by key
body: <p>I have the following Java code:</p>
  
  <pre><code>List&lt;BaseQuery&gt; queries; 
  
  Map&lt;Long, List&lt;BaseQuery&gt;&gt; map = new HashMap&lt;&gt;();
  for (BaseQuery query : queries) {
      List&lt;BaseQuery&gt; queryList = map.get(query.getCharacteristicId());
      if(queryList == null) {
          queryList = new ArrayList&lt;&gt;();
          map.put(query.getCharacteristicId(), queryList);
      }
      queryList.add(query);
  }
  </code></pre>
  
  <p>Could you please show how to convert it to Java 8 and streams?</p>