title: Lowercase all HashMap keys
body: <p>I 've run into a scenario where I want to lowercase all the keys of a HashMap (don't ask why, I just have to do this). The HashMap has some millions of entries.</p>
  
  <p>At first, I thought I 'd just create a new Map, iterate over the entries of the map that is to be lowercased, and add the respective values. This task should run only once per day or something like that, so I thought I could bare this.</p>
  
  <pre><code>Map&lt;String, Long&gt; lowerCaseMap = new HashMap&lt;&gt;(myMap.size());
  for (Map.Entry&lt;String, Long&gt; entry : myMap.entrySet()) {
     lowerCaseMap.put(entry.getKey().toLowerCase(), entry.getValue());
  }
  </code></pre>
  
  <p>this, however, caused some OutOfMemory errors when my server was overloaded during this one time that I was about to copy the Map.</p>
  
  <p>Now my question is, how can I accomplish this task with the smallest memory footprint? </p>
  
  <p>Would removing each key after lowercased - added to the new Map help?</p>
  
  <p>Could I utilize java8 streams to make this faster? (e.g something like this)</p>
  
  <pre><code>Map&lt;String, Long&gt; lowerCaseMap = myMap.entrySet().parallelStream().collect(Collectors.toMap(entry -&gt; entry.getKey().toLowerCase(), Map.Entry::getValue));
  </code></pre>
  
  <p><strong>Update</strong>
  It seems that it's a <code>Collections.unmodifiableMap</code> so I don't have the option of </p>
  
  <blockquote>
    <p>removing each key after lowercased - added to the new Map</p>
  </blockquote>