title: Common class for indexing an array to a map by IDs
body: <p>I got lot of cases in my code where I have to access data from a DB using Hibernate and receive the results as a list. Most often this data is cached and accessed by ID. So obviously, I have to convert it into a Map for quick results, as iterating over it every time would be an O(n) nightmare.</p>
  
  <p>The question isn't how to do that, the process is fairly trivial:</p>
  
  <pre><code>Map&lt;Integer, ProjectEntry&gt; projectEntries = new HashMap&lt;&gt;();
  for (ProjectEntry p : projectService.listProjectEntries()) {
      projectEntries.put(p.getId(), p);
  }
  </code></pre>
  
  <p>What I wonder is if there's already a feature for this in common Java libraries, because I have to repeat this code over and over and would love to reduce it to a single line. It seems like such a common use case.</p>