title: Java: Putting items from List into HashMap efficiently
body: <p>I have a list here:</p>
  
  <pre><code>List&lt;QueryStrings&gt; queryStrings
  </code></pre>
  
  <p>and QueryStrings is just a simple class </p>
  
  <pre><code>public class QueryStrings {
      private Integer id;
      private String rel;
      private String impl;
  }
  </code></pre>
  
  <p>I need to put the List into a HashMap where the id will be the key, I am doing it like this right now, looping the List one item at a time:</p>
  
  <pre><code>HashMap&lt;Integer, QueryStrings&gt; queryMap = new HashMap&lt;&gt;();
  for (QueryStrings element : queryStrings) {
      Integer thisId = Integer.parseInt(element.getId());
      queryMap.put(thisId, element);
  }
  </code></pre>
  
  <p>Is there a better way to this? I do not want to loop each items, is that possible?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Sorry I should not parse the integer, so the code should look like:</p>
  
  <pre><code>HashMap&lt;Integer, QueryStrings&gt; queryMap = new HashMap&lt;&gt;();
  for (QueryStrings element : queryStrings) {
      queryMap.put(element.getId(), element);
  }
  </code></pre>