title: Java 8 : how to extract a HashMap from a ArrayList of HashMap in Java 8 using streams?
body: <p>I have the following sample result when I query a database : </p>
  
  <pre><code>dataList  = [{ name : name1, rollno: rollno1 }, { name : name2, rollno: rollno2 } ]
  </code></pre>
  
  <p>I want to convert this list of hashmaps into a single hashmap using Java 8 streams.
  I tried using Collectors.toMap() but i am not sure how to refer to rollNo as key and the hashmap as the value inside the toMap method.</p>
  
  <p>Exected output : </p>
  
  <pre><code>{ rollno1 : { name : name1, rollno: rollno1 } , rollno2 : { name : name2, rollno: rollno2 } }
  </code></pre>
  
  <p>I tried doing it using a for each loop on the list and then adding the rollno as key to a hashmap and the hashmap as value itself of that rollno.</p>
  
  <pre><code>
      HashMap&lt;String,HashMap&lt;String,String&gt;&gt; newMap = new HashMap();
  
      for(HashMap&lt;String,String&gt; record : dataList){
          String key = record.get("rollno").toString();
          newMap.put(key,record);
      }
  
  </code></pre>
  
  <p>Is there a way to refactor this code using functional streams in Java 8?
  Will using streams collect method give any performance advantage over the foreach for doing this?</p>
  
  <p>Will appreciate any leads. Thanks</p>